{/* Sursa Pascal Problema "Segment"
  * Complexitate: O(N * lg MAXC)
  */}
type entry =record
      x, y1, y2, sgn:integer;
     end;
     sir = array[0..50000]of entry;

var a:sir;
    i, n, x1, y1, x2, y2, v : word;
    T : array[0..131072]of word;
    Res: Int64;

function cmp (i, j : entry):integer;
begin
    if i.x <> j.x then cmp:=i.x-j.x
    else cmp:=j.sgn - i.sgn;
end;

function query (n,l,r,a,b :word):word;
var m, tt:word;
begin
 tt := 0;
 if (a <= l)and(r <= b) then tt:=T[n]
 else begin
   m := (l + r) div 2;
   if (a <= m) then
     tt:=tt+query(2 * n, l, m, a, b);
   if (b > m) then 
   tt:=tt+query(2*n+1, m+1, r, a, b);
 end;
    query := tt;
end;

procedure update(n, l, r, p,v: word);
var m : word;
begin
 m := (l + r) div 2;
 inc(T[n],v);
 if (l < r)  then begin
   if (p <= m) then 
      update(2 * n, l, m, p, v)
   else 
      update(2*n + 1, m + 1, r, p, v);
 end;
end;

procedure QuickSort(var A: sir; Lo, Hi: Integer);

procedure Sort(l, r: Integer);
var i, j: integer; x, y : entry;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
   while cmp(a[i],x)<0 do i:= i + 1;
   while cmp(x,a[j])<0 do j:= j - 1;
   if i <= j then begin
      y:=a[i]; a[i]:=a[j];a[j] := y;
      i := i + 1; j := j - 1;
   end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;

begin  
  Sort(Lo,Hi); 
end;

begin
    assign(input, 'segment.in');
    reset(input); readln(n); v:=0;
    for i := 0 to N - 1 do begin
      readln(x1, y1, x2, y2);
      if (y1 = y2) then begin
        A[v].x := x1; A[v].sgn := +1;  
        A[v].y1 := y1; inc(v);
        A[v].x := x2; A[v].sgn := -1;  
        A[v].y1 := y1; inc(v); end
      else
        if (x1 = x2) then begin
          A[v].x := x1; A[v].sgn := 0;
          A[v].y1:=y1; A[v].y2 := y2; 
          inc(v); end;
    end;
   close(input);QuickSort(A, 0, v-1);
   Res:=0;
   for i := 0 to v - 1 do begin
     if (A[i].sgn = 0)  then
		Res:=Res+query(1,0,49999,A[i].y1,A[i].y2)
    else
   update(1,0,49999, A[i].y1,A[i].sgn);
   end;
   assign(output, 'segment.out'); rewrite(output);  writeln(Res); close(output); 
end.

