/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet();
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].set(a);
         }
         long res = 0L;
         if(N >= 2000)
            for(int i=0; i < N; i++)
               for(int a=i+1; a < N; a++)
               {
                  BitSet temp = bsets[i];
                  temp.and(bsets[a]);
                  int bitcnt = temp.cardinality();
                  res += (long)bitcnt*(bitcnt-1);
               }
         else
            for(int i=0; i < N; i++)
               for(int a=i+1; a < N; a++)
               {
                  BitSet temp = (BitSet)(bsets[i].clone());
                  temp.and(bsets[a]);
                  int bitcnt = temp.cardinality();
                  res += (long)bitcnt*(bitcnt-1);
               }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E2
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet(2502);
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].add(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               int bitcnt = bsets[i].and(bsets[a]);
               res += (long)bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }
   class BitSet
   {
      public long[] sets;
      public int size;

      public BitSet(int N)
      {
         size = N;
         if(N%64 == 0)
            sets = new long[N/64];
         else
            sets = new long[N/64+1];
      }
      public void add(int i)
      {
         int dex = i/64;
         int thing = i%64;
         sets[dex] |= (1L << thing);
      }
      public int and(BitSet oth)
      {
         int boof = Math.min(sets.length, oth.sets.length);
         int res = 0;
         for(int i=0; i < boof; i++)
            res += Long.bitCount(sets[i] & oth.sets[i]);
         return res;
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E2
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet(5001);
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].add(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               int bitcnt = bsets[i].and(bsets[a]);
               res += (long)bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }
   class BitSet
   {
      public long[] sets;
      public int size;

      public BitSet(int N)
      {
         size = N;
         if(N%64 == 0)
            sets = new long[N/64];
         else
            sets = new long[N/64+1];
      }
      public void add(int i)
      {
         int dex = i/64;
         int thing = i%64;
         sets[dex] |= (1L << thing);
      }
      public int and(BitSet oth)
      {
         int boof = Math.min(sets.length, oth.sets.length);
         int res = 0;
         for(int i=0; i < boof; i++)
            res += Long.bitCount(sets[i] & oth.sets[i]);
         return res;
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet();
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].set(a);
         }
         long res = 0L;
         if(N >= 2000)
            for(int i=0; i < N; i++)
               for(int a=i+1; a < N; a++)
               {
                  BitSet temp = bsets[i];
                  temp.and(bsets[a]);
                  int bitcnt = temp.cardinality();
                  res += bitcnt*(bitcnt-1);
               }
         else
            for(int i=0; i < N; i++)
               for(int a=i+1; a < N; a++)
               {
                  BitSet temp = (BitSet)(bsets[i].clone());
                  temp.and(bsets[a]);
                  int bitcnt = temp.cardinality();
                  res += bitcnt*(bitcnt-1);
               }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E2
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet(2000);
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].add(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               int bitcnt = bsets[i].and(bsets[a]);
               res += (long)bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }
   class BitSet
   {
      public long[] sets;
      public int size;

      public BitSet(int N)
      {
         size = N;
         if(N%64 == 0)
            sets = new long[N/64];
         else
            sets = new long[N/64+1];
      }
      public void add(int i)
      {
         int dex = i/64;
         int thing = i%64;
         sets[dex] |= (1L << thing);
      }
      public int and(BitSet oth)
      {
         int boof = Math.min(sets.length, oth.sets.length);
         int res = 0;
         for(int i=0; i < boof; i++)
            res += Long.bitCount(sets[i] & oth.sets[i]);
         return res;
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet();
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].set(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               BitSet temp = (BitSet)(bsets[i].clone());
               temp.and(bsets[a]);
               int bitcnt = temp.cardinality();
               res += bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet();
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].set(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               BitSet temp = bsets[i];//(BitSet)(bsets[i].clone());
               temp.and(bsets[a]);
               int bitcnt = temp.cardinality();
               res += bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E2
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet(M);
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].add(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               int bitcnt = bsets[i].and(bsets[a]);
               res += (long)bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }
   class BitSet
   {
      public long[] sets;
      public int size;

      public BitSet(int N)
      {
         size = N;
         if(N%64 == 0)
            sets = new long[N/64];
         else
            sets = new long[N/64+1];
      }
      public void add(int i)
      {
         int dex = i/64;
         int thing = i%64;
         sets[dex] |= (1L << thing);
      }
      public int and(BitSet oth)
      {
         int boof = Math.min(sets.length, oth.sets.length);
         int res = 0;
         for(int i=0; i < boof; i++)
            res += Long.bitCount(sets[i] & oth.sets[i]);
         return res;
      }
   }


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;

   public class x1194E
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         ArrayList<Segment> hor = new ArrayList<Segment>();
         ArrayList<Segment> ver = new ArrayList<Segment>();
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int ab = Integer.parseInt(st.nextToken());
            int ac = Integer.parseInt(st.nextToken());
            int ad = Integer.parseInt(st.nextToken());
            Segment b = new Segment(a,ab,ac,ad);
            if(a == ac)
               ver.add(b);
            else
               hor.add(b);
         }
         if(ver.size() <= hor.size())
            System.out.println(bash(ver, hor));
         else
            System.out.println(bash(hor, ver));
      }
      public static long bash(ArrayList<Segment> ls, ArrayList<Segment> ls2)
      {
         int N = ls.size();
         int M = ls2.size();
         BitSet[] bsets = new BitSet[N];
         for(int i=0; i < N; i++)
         {
            bsets[i] = new BitSet();
            for(int a=0; a < M; a++)
               if(cross(ls.get(i), ls2.get(a)))
                  bsets[i].set(a);
         }
         long res = 0L;
         for(int i=0; i < N; i++)
            for(int a=i+1; a < N; a++)
            {
               BitSet temp = bsets[i];
               if(N >= 2000)
                  temp = (BitSet)(bsets[i].clone());
               temp.and(bsets[a]);
               int bitcnt = temp.cardinality();
               res += bitcnt*(bitcnt-1);
            }
         return res/2;
      }
      public static boolean cross(Segment s1, Segment s2)
      {
         if(s1.y1 == s1.y2)
            return (s2.x1 >= s1.x1) && (s2.x1 <= s1.x2) && (s1.y1 >= s2.y1) && (s1.y2 <= s2.y2);
         else
            return (s1.x1 >= s2.x1) && (s1.x1 <= s2.x2) && (s2.y1 >= s1.y1) && (s2.y2 <= s1.y2);
      }
   }
   class Segment
   {
      public int x1;
      public int y1;
      public int x2;
      public int y2;

      public Segment(int a, int b, int c, int d)
      {
         x1 = Math.min(a, c);
         y1 = Math.min(b, d);
         x2 = Math.max(a, c);
         y2 = Math.max(b, d);
      }
   }


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rustam Musin (t.me/musin_acm)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        EPoschitaiteChetirehugolniki solver = new EPoschitaiteChetirehugolniki();
        solver.solve(1, in, out);
        out.close();
    }

    static class EPoschitaiteChetirehugolniki {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int offset = 5000;
            int n = in.readInt();
            List<Segment> vertical = new ArrayList<>();
            List<Segment> horizontal = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x0 = in.readInt() + offset;
                int y0 = in.readInt() + offset;
                int x1 = in.readInt() + offset;
                int y1 = in.readInt() + offset;
                Segment segment = createSegment(x0, x1, y0, y1);
                if (segment.isVertical()) {
                    vertical.add(segment);
                } else {
                    horizontal.add(segment);
                }
            }
            horizontal.sort(Comparator.comparingInt(s -> s.minY));
            vertical.sort(Comparator.comparingInt(s -> s.maxY));
            Fenwick tree = new Fenwick(offset * 2 + 1);
            long answer = 0;
            for (int i = 0; i < horizontal.size(); i++, tree.clear()) {
                Segment h0 = horizontal.get(i);
                List<Segment> added = new ArrayList<>();
                for (Segment s : vertical) {
                    if (s.minY <= h0.minY) {
                        tree.add(s.minX, 1);
                        added.add(s);
                    }
                }
                int atAdded = 0;
                for (int j = i + 1; j < horizontal.size(); j++) {
                    Segment h1 = horizontal.get(j);
                    IntIntPair inter = intersect(h0.minX, h0.maxX, h1.minX, h1.maxX);
                    if (h1.minY == h0.minY || inter.first >= inter.second) {
                        continue;
                    }
                    while (atAdded < added.size() && added.get(atAdded).maxY < h1.minY) {
                        Segment rem = added.get(atAdded++);
                        tree.add(rem.minX, -1);
                    }
                    answer += pairs(tree.get(inter.first, inter.second));
                }
            }
            out.print(answer);
        }

        long pairs(long n) {
            return n * (n - 1) / 2;
        }

        IntIntPair intersect(int a1, int b1, int a2, int b2) {
            return IntIntPair.makePair(Math.max(a1, a2), Math.min(b1, b2));
        }

        Segment createSegment(int x0, int x1, int y0, int y1) {
            if (x0 > x1) {
                return createSegment(x1, x0, y0, y1);
            }
            if (y0 > y1) {
                return createSegment(x0, x1, y1, y0);
            }
            return new Segment(x0, y0, x1, y1);
        }

        class Segment {
            int minX;
            int minY;
            int maxX;
            int maxY;

            Segment(int minX, int minY, int maxX, int maxY) {
                this.minX = minX;
                this.minY = minY;
                this.maxX = maxX;
                this.maxY = maxY;
            }

            boolean isVertical() {
                return minX == maxX;
            }

        }

        class Fenwick {
            int[] tree;

            Fenwick(int n) {
                tree = new int[n + 1];
            }

            int get(int at) {
                int s = 0;
                for (at++; at > 0; at -= at & -at) {
                    s += tree[at];
                }
                return s;
            }

            int get(int l, int r) {
                return get(r) - get(l - 1);
            }

            void add(int at, int x) {
                for (at++; at < tree.length; at += at & -at) {
                    tree[at] += x;
                }
            }

            void clear() {
                Arrays.fill(tree, 0);
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }

    static class IntIntPair implements Comparable<IntIntPair> {
        public final int first;
        public final int second;

        public static IntIntPair makePair(int first, int second) {
            return new IntIntPair(first, second);
        }

        public IntIntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            IntIntPair pair = (IntIntPair) o;

            return first == pair.first && second == pair.second;
        }

        public int hashCode() {
            int result = first;
            result = 31 * result + second;
            return result;
        }

        public String toString() {
            return "(" + first + "," + second + ")";
        }

        public int compareTo(IntIntPair o) {
            int value = Integer.compare(first, o.first);
            if (value != 0) {
                return value;
            }
            return Integer.compare(second, o.second);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Rustam Musin (t.me/musin_acm)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        EPoschitaiteChetirehugolniki solver = new EPoschitaiteChetirehugolniki();
        solver.solve(1, in, out);
        out.close();
    }

    static class EPoschitaiteChetirehugolniki {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int offset = 5000;
            int n = in.readInt();
            List<Segment> vertical = new ArrayList<>();
            List<Segment> horizontal = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x0 = in.readInt() + offset;
                int y0 = in.readInt() + offset;
                int x1 = in.readInt() + offset;
                int y1 = in.readInt() + offset;
                Segment segment = createSegment(x0, x1, y0, y1);
                if (segment.isVertical()) {
                    vertical.add(segment);
                } else {
                    horizontal.add(segment);
                }
            }
            horizontal.sort(Comparator.comparingInt(s -> s.minX));
            vertical.sort(Comparator.comparingInt(s -> s.maxY));
            Fenwick tree = new Fenwick(offset * 2 + 1);
            long answer = 0;
            for (int i = 0; i < horizontal.size(); i++, tree.clear()) {
                Segment h0 = horizontal.get(i);
                List<Segment> added = new ArrayList<>();
                for (Segment s : vertical) {
                    if (s.minY <= h0.minY) {
                        tree.add(s.minX, 1);
                        added.add(s);
                    }
                }
                int atAdded = 0;
                for (int j = i + 1; j < horizontal.size(); j++) {
                    Segment h1 = horizontal.get(j);
                    IntIntPair inter = intersect(h0.minX, h0.maxX, h1.minX, h1.maxX);
                    if (h1.minY == h0.minY || inter.first >= inter.second) {
                        continue;
                    }
                    while (atAdded < added.size() && added.get(atAdded).maxY < h1.minY) {
                        Segment rem = added.get(atAdded++);
                        tree.add(rem.minX, -1);
                    }
                    answer += pairs(tree.get(inter.first, inter.second));
                }
            }
            out.print(answer);
        }

        long pairs(long n) {
            return n * (n - 1) / 2;
        }

        IntIntPair intersect(int a1, int b1, int a2, int b2) {
            return IntIntPair.makePair(Math.max(a1, a2), Math.min(b1, b2));
        }

        Segment createSegment(int x0, int x1, int y0, int y1) {
            if (x0 > x1) {
                return createSegment(x1, x0, y0, y1);
            }
            if (y0 > y1) {
                return createSegment(x0, x1, y1, y0);
            }
            return new Segment(x0, y0, x1, y1);
        }

        class Segment {
            int minX;
            int minY;
            int maxX;
            int maxY;

            Segment(int minX, int minY, int maxX, int maxY) {
                this.minX = minX;
                this.minY = minY;
                this.maxX = maxX;
                this.maxY = maxY;
            }

            boolean isVertical() {
                return minX == maxX;
            }

        }

        class Fenwick {
            int[] tree;

            Fenwick(int n) {
                tree = new int[n + 1];
            }

            int get(int at) {
                int s = 0;
                for (at++; at > 0; at -= at & -at) {
                    s += tree[at];
                }
                return s;
            }

            int get(int l, int r) {
                return get(r) - get(l - 1);
            }

            void add(int at, int x) {
                for (at++; at < tree.length; at += at & -at) {
                    tree[at] += x;
                }
            }

            void clear() {
                Arrays.fill(tree, 0);
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(long i) {
            writer.print(i);
        }

    }

    static class IntIntPair implements Comparable<IntIntPair> {
        public final int first;
        public final int second;

        public static IntIntPair makePair(int first, int second) {
            return new IntIntPair(first, second);
        }

        public IntIntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            IntIntPair pair = (IntIntPair) o;

            return first == pair.first && second == pair.second;
        }

        public int hashCode() {
            int result = first;
            result = 31 * result + second;
            return result;
        }

        public String toString() {
            return "(" + first + "," + second + ")";
        }

        public int compareTo(IntIntPair o) {
            int value = Integer.compare(first, o.first);
            if (value != 0) {
                return value;
            }
            return Integer.compare(second, o.second);
        }

    }
}


import java.io.*;
import java.util.*;

public class Main {

    static int maxn = 5001;

    static class Node {
        int x1, x2, y1, y2;
        public Node(int x1, int x2, int y1, int y2){
            this.x1 = x1;
            this.x2 = x2;
            this.y1 = y1;
            this.y2 = y2;
        }
    }

    static class BIT {
        int[] c;
        int size;

        public BIT(int size) {
            c = new int[size + 1];
            this.size = size + 1;
        }

        public int get(int x) {
            int sum = 0;
            for (; x > 0; x -= x & (-x)) {
                sum += c[x];
            }
            return sum;
        }

        public void update(int x, int val) {
            for (; x < size; x += x & (-x)) {
                c[x] += val;
            }
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<Node> hlist = new ArrayList<>();
        ArrayList<Node> vlist = new ArrayList<>();

        int x1, x2, y1, y2;
        for (int i = 0; i < n; i++) {
            x1 = input.nextInt() + maxn;
            y1 = input.nextInt() + maxn;
            x2 = input.nextInt() + maxn;
            y2 = input.nextInt() + maxn;
            if (x1 > x2) { int tmp = x1; x1 = x2; x2 = tmp; }
            if (y1 > y2) { int tmp = y1; y1 = y2; y2 = tmp; }
            if (x1 == x2) vlist.add(new Node(x1, x2, y1, y2));
            else hlist.add(new Node(x1, x2, y1, y2));
        }
        Collections.sort(hlist, (a, b) -> a.y1 - b.y1);
        Collections.sort(vlist, (a, b) -> b.y2 - a.y2);

        long ans = 0;
        for (int i = 0; i < hlist.size(); i++) {
            Node x = hlist.get(i);
            BIT bit = new BIT(2 * maxn);
            Stack<Node> stk = new Stack<>();
            for (int j = 0; j < vlist.size(); j++) {
                Node y = vlist.get(j);
                if (y.y1 <= x.y1 && x.x1 <= y.x1 && y.x1 <= x.x2) {
                    bit.update(y.x1, 1);
                    stk.push(y);
                }
            }
            for (int j = i + 1; j < hlist.size(); j++) {
                Node y = hlist.get(j);
                while (!stk.empty()) {
                    Node cur = stk.peek();
                    if (cur.y2 < y.y2) {
                        bit.update(cur.x1, -1);
                        stk.pop();
                    }
                    else break;
                }
                int l = Math.max(x.x1, y.x1);
                int r = Math.min(x.x2, y.x2);
                if (l > r) continue;
                long cnt = bit.get(r) - bit.get(l - 1);
                ans += cnt * (cnt - 1) / 2;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class Solution{

    private int N = 10009;

    // fenwick
    private int [] f;
    private int getSum(int index){
        int sum = 0;
        while(index >= 0){
            sum += f[index];
            index = (index & (index + 1)) - 1;
        }
        return sum;
    }
    private void fupdate(int index, int val){
        while(index < N){
            f[index] += val;
            index |= (index + 1);
        }
    }

    public void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, List<int[]>> hor = new HashMap<>();
        Map<Integer, List<int[]>> vert = new HashMap<>();
        while(n-- > 0){
            int x1 = sc.nextInt() + 5000;
            int y1 = sc.nextInt() + 5000;
            int x2 = sc.nextInt() + 5000;
            int y2 = sc.nextInt() + 5000;
            if(x1 == x2){
                vert.putIfAbsent(x1, new ArrayList<>());
                vert.get(x1).add(new int[]{Math.min(y1, y2), Math.max(y1, y2)});
            }else{
                hor.putIfAbsent(y1, new ArrayList<>());
                hor.get(y1).add(new int[]{Math.min(x1, x2), Math.max(x1, x2)});
            }
        }
        long ans = 0;
        for(int i = 0; i < N; i++){
            if(hor.containsKey(i) == false) continue;
            for(int [] curh: hor.get(i)){
                Map<Integer, List<Integer>> d = new HashMap<>();
                this.f = new int[N];
                int left = curh[0];
                int right = curh[1];
                for(int l = left; l <= right; l++){
                    if(vert.containsKey(l) == false) continue;
                    for(int [] curv: vert.get(l)){
                        int lower = curv[0];
                        int higher = curv[1];
                        if(lower <= i && higher > i){
                            fupdate(l, 1);
                            d.putIfAbsent(higher, new ArrayList<>());
                            d.get(higher).add(l);
                        }
                    }
                }
                for(int i2 = i + 1; i2 < N; i2++){
                    if(hor.containsKey(i2) == false) continue;
                    for(int [] curh2: hor.get(i2)){
                        int cur = getSum(curh2[1]) - getSum(curh2[0] - 1);
                        ans += ((cur - 1) * cur) / 2;
                    }
                    if(d.containsKey(i2) == true){
                        for(int x: d.get(i2)){
                            fupdate(x, -1);
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
    public static void main(String [] args){
        new  Solution().solve();
    }
}


import java.util.*;
public class Solution{

    private int N = 10009;

    // fenwick
    private int [] f;
    private int getSum(int index){
        int sum = 0;
        while(index >= 0){
            sum += f[index];
            index = (index & (index + 1)) - 1;
        }
        return sum;
    }
    private void fupdate(int index, int val){
        while(index < N){
            f[index] += val;
            index |= (index + 1);
        }
    }

    public void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<List<int[]>> hor = new ArrayList<>();
        List<List<int[]>> vert = new ArrayList<>();
        for(int i = 0; i < N; i++){
            hor.add(new ArrayList<>());
            vert.add(new ArrayList<>());
        }
        while(n-- > 0){
            int x1 = sc.nextInt() + 5000;
            int y1 = sc.nextInt() + 5000;
            int x2 = sc.nextInt() + 5000;
            int y2 = sc.nextInt() + 5000;
            if(x1 == x2){
                vert.get(x1).add(new int[]{Math.min(y1, y2), Math.max(y1, y2)});
            }else{
                hor.get(y1).add(new int[]{Math.min(x1, x2), Math.max(x1, x2)});
            }
        }
        long ans = 0;
        for(int i = 0; i < N; i++){
            for(int [] curh: hor.get(i)){
                List<List<Integer>> d = new ArrayList<>();
                for(int j = 0; j < N; j++){
                    d.add(new ArrayList<>());
                }
                this.f = new int[N];
                int left = curh[0];
                int right = curh[1];
                for(int l = left; l <= right; l++){
                    for(int [] curv: vert.get(l)){
                        int lower = curv[0];
                        int higher = curv[1];
                        if(lower <= i && higher > i){
                            fupdate(l, 1);
                            d.get(higher).add(l);
                        }
                    }
                }
                for(int i2 = i + 1; i2 < N; i2++){
                    for(int [] curh2: hor.get(i2)){
                        int cur = getSum(curh2[1]) - getSum(curh2[0] - 1);
                        ans += ((cur - 1) * cur) / 2;
                    }
                    for(int x: d.get(i2)){
                        fupdate(x, -1);
                    }
                }
            }
        }
        System.out.println(ans);
    }
    public static void main(String [] args){
        new  Solution().solve();
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    int N = 10002;
    int maxn = 5001;
    int [] f;

    private int sum(int index){
        int sum = 0;
        while(index > 0){
            sum += f[index];
            index -= (index & (-index));
        }
        return sum;
    }

    public void fupdate(int index, int val){
        while(index < N){
            f[index]+=val;
            index += (index & (-index));
        }
    }

    public void solve(){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        List<int[]> hlist = new ArrayList<>();
        List<int[]> vlist = new ArrayList<>();

        int x1, x2, y1, y2;
        for (int i = 0; i < n; i++) {
            x1 = input.nextInt() + maxn;
            y1 = input.nextInt() + maxn;
            x2 = input.nextInt() + maxn;
            y2 = input.nextInt() + maxn;
            if (x1 > x2) {
                int tmp = x1; x1 = x2; x2 = tmp;
            }
            if (y1 > y2) {
                int tmp = y1; y1 = y2; y2 = tmp;
            }
            if (x1 == x2) {
                vlist.add(new int[]{x1, x2, y1, y2});
            }else{
                hlist.add(new int[]{x1, x2, y1, y2});
            }
        }
        Collections.sort(hlist, (a, b) -> a[2] - b[2]);
        Collections.sort(vlist, (a, b) -> b[3] - a[3]);

        long ans = 0;
        for (int i = 0; i < hlist.size(); i++) {
            int [] x = hlist.get(i);
            f = new int[N];
            Stack<int[]> stk = new Stack<>();
            for (int j = 0; j < vlist.size(); j++) {
                int [] y = vlist.get(j);
                if (y[2] <= x[2] && x[0] <= y[0] && y[0] <= x[1]) {
                    fupdate(y[0], 1);
                    stk.push(y);
                }
            }
            for (int j = i + 1; j < hlist.size(); j++) {
                int [] y = hlist.get(j);
                while (!stk.empty()) {
                    int [] cur = stk.peek();
                    if (cur[3] < y[3]) {
                        fupdate(cur[0], -1);
                        stk.pop();
                    }else{
                        break;
                    }
                }
                int l = Math.max(x[0], y[0]);
                int r = Math.min(x[1], y[1]);
                if (l > r) continue;
                long cnt = sum(r) - sum(l - 1);
                ans += cnt * (cnt - 1) / 2;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Solution().solve();
    }
}


import java.io.*;
import java.util.*;

public class Solution {

    int N = 10002;
    int maxn = 5001;
    int [] f;

    private int sum(int index){
        int sum = 0;
        while(index > 0){
            sum += f[index];
            index -= (index & (-index));
        }
        return sum;
    }

    public void fupdate(int index, int val){
        while(index < N){
            f[index]+=val;
            index += (index & (-index));
        }
    }

    public void solve(){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        List<int[]> hlist = new ArrayList<>();
        List<int[]> vlist = new ArrayList<>();

        int x1, x2, y1, y2;
        for (int i = 0; i < n; i++) {
            x1 = input.nextInt() + maxn;
            y1 = input.nextInt() + maxn;
            x2 = input.nextInt() + maxn;
            y2 = input.nextInt() + maxn;
            if (x1 > x2) {
                int tmp = x1; x1 = x2; x2 = tmp;
            }
            if (y1 > y2) {
                int tmp = y1; y1 = y2; y2 = tmp;
            }
            if (x1 == x2) {
                vlist.add(new int[]{x1, x2, y1, y2});
            }else{
                hlist.add(new int[]{x1, x2, y1, y2});
            }
        }
        Collections.sort(hlist, (a, b) -> a[2] - b[2]);
        Collections.sort(vlist, (a, b) -> b[3] - a[3]);

        long ans = 0;
        for (int i = 0; i < hlist.size(); i++) {
            int [] x = hlist.get(i);
            f = new int[N];
            Stack<int[]> stk = new Stack<>();
            for (int j = 0; j < vlist.size(); j++) {
                int [] y = vlist.get(j);
                if (y[2] <= x[2] && x[0] <= y[0] && y[0] < x[1]) {
                    fupdate(y[0], 1);
                    stk.push(y);
                }
            }
            for (int j = i + 1; j < hlist.size(); j++) {
                int [] y = hlist.get(j);
                while (!stk.empty()) {
                    int [] cur = stk.peek();
                    if (cur[3] < y[3]) {
                        fupdate(cur[0], -1);
                        stk.pop();
                    }else{
                        break;
                    }
                }
                int l = Math.max(x[0], y[0]);
                int r = Math.min(x[1], y[1]);
                if (l > r) continue;
                long cnt = sum(r) - sum(l - 1);
                ans += cnt * (cnt - 1) / 2;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Solution().solve();
    }
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	int[] A;
	int maxn=5001;
	void work() {
		int n=ni();
		ArrayList<int[]> l1=new ArrayList<>();
		ArrayList<int[]> l2=new ArrayList<>();
		for(int i=0;i<n;i++) {
			int[] A=nia(4);
			if(A[0]==A[2]) {
				l2.add(new int[] {A[0],Math.min(A[1], A[3]),A[2],Math.max(A[1], A[3])});
			}else {
				l1.add(new int[] {Math.min(A[0], A[2]),A[1],Math.max(A[0], A[2]),A[3]});
			}
		}
		Collections.sort(l1,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A1[1]-A2[1];
			}
		});
		Collections.sort(l2,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A2[3]-A1[3];//上端点
			}
		});
		long ret=0;
		for(int i=0;i<l1.size();i++) {
			A=new int[10003];
			for(int j=l1.size()-1,k=0;j>i;j--) {
				int s=Math.max(l1.get(i)[0], l1.get(j)[0]);
				int e=Math.min(l1.get(i)[2], l1.get(j)[2]);
				if(s>=e)continue;
				while(k<l2.size()&&l2.get(k)[3]>=l1.get(j)[1]) {
					if(l2.get(k)[1]<=l1.get(i)[1]) {
						update(l2.get(k)[0],1);
					}
					k++;
				}
				long v=query(s,e);
				ret+=v*(v-1)/2;
			}
		}
		out.println(ret);
	}

	private long query(int s, int e) {
		return query(e)-query(s-1);
	}

	long query(int x) {
		long ret=0;
		for(;x>0;x-=lowbit(x)) {
			ret+=A[x];
		}
		return ret;
	}

	int lowbit(int x){
		return x&-x;
	}

	private void update(int x, int v) {
		for(;x<10003;x+=lowbit(x)) {
			A[x]+=v;
		}
	}

	//input
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
		}
		return graph;
	}

	private ArrayList<long[]>[] ngw(int n, int m) {
		ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
			graph[(int)s].add(new long[] {e,w});
			graph[(int)e].add(new long[] {s,w});
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt()+maxn;
		}
		return A;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next()
	{
		while(st==null || !st.hasMoreElements())//回车，空行情况
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt()
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	int[] sum;
	void work() {
		int n=ni();
		ArrayList<int[]> l1=new ArrayList<>();
		ArrayList<int[]> l2=new ArrayList<>();
		for(int i=0;i<n;i++) {
			int[] A=nia(4);
			if(A[0]==A[2]) {
				l2.add(new int[] {A[0],Math.min(A[1], A[3]),A[2],Math.max(A[1], A[3])});
			}else {
				l1.add(new int[] {Math.min(A[0], A[2]),A[1],Math.max(A[0], A[2]),A[3]});
			}
		}
		Collections.sort(l1,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A1[1]-A2[1];
			}
		});
		Collections.sort(l2,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A2[3]-A1[3];//上端点
			}
		});
		long ret=0;
		for(int i=0;i<l1.size();i++) {
			sum=new int[40001];
			for(int j=l1.size()-1,k=0;j>i;j--) {
				int s=Math.max(l1.get(i)[0], l1.get(j)[0]);
				int e=Math.min(l1.get(i)[2], l1.get(j)[2]);
				if(s>=e)continue;
				while(k<l2.size()&&l2.get(k)[3]>=l1.get(j)[1]) {
					if(l2.get(k)[1]<=l1.get(i)[1]) {
						insert(1,-5005,5005,l2.get(k)[0]);
					}
					k++;
				}
				long v=query(1,-5005,5005,s,e);
				ret+=v*(v-1)/2;
			}
		}
		out.println(ret);
	}

	private long query(int idx, int l, int r, int s, int e) {
		if(s<=l&&r<=e) {
			return sum[idx];
		}
		int m=l+(r-l)/2;
		int ret=0;
		if(m>=s) {
			ret+=query(idx<<1,l,m,s,e);
		}
		if(m+1<=e) {
			ret+=query((idx<<1)+1,m+1,r,s,e);
		}
		return ret;
	}
	private void insert(int idx,int l,int r,int k) {
		if(l==r) {
			sum[idx]++;
			return;
		}
		int m=l+(r-l)/2;
		if(k<=m) {
			insert(idx<<1,l,m,k);
		}else {
			insert((idx<<1)+1,m+1,r,k);
		}
		sum[idx]=sum[idx<<1]+sum[(idx<<1)+1];
	}

	//input
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
		}
		return graph;
	}

	private ArrayList<long[]>[] ngw(int n, int m) {
		ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
			graph[(int)s].add(new long[] {e,w});
			graph[(int)e].add(new long[] {s,w});
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt();
		}
		return A;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next()
	{
		while(st==null || !st.hasMoreElements())//回车，空行情况
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt()
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	ArrayList<Integer>[] graph;
	int[] degree;
	int[][] ret;
	int[][] dir=new int[][] {{0,1},{1,0},{0,-1},{-1,0}};
	void work() {
		int n=ni();
		ArrayList<int[]> l1=new ArrayList<>();
		ArrayList<int[]> l2=new ArrayList<>();
		for(int i=0;i<n;i++) {
			int[] A=nia(4);
			if(A[0]==A[2]) {
				l2.add(new int[] {A[0],Math.min(A[1], A[3]),A[2],Math.max(A[1], A[3])});
			}else {
				l1.add(new int[] {Math.min(A[0], A[2]),A[1],Math.max(A[0], A[2]),A[3]});
			}
		}
		Collections.sort(l1,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A1[1]-A2[1];
			}
		});
		Collections.sort(l2,new Comparator<int[]>() {
			public int compare(int[] A1,int[] A2) {
				return A2[3]-A1[3];//上端点
			}
		});
		long ret=0;
		for(int i=0;i<l1.size();i++) {
			Node root=new Node();
			for(int j=l1.size()-1,k=0;j>i;j--) {
				int s=Math.max(l1.get(i)[0], l1.get(j)[0]);
				int e=Math.min(l1.get(i)[2], l1.get(j)[2]);
				if(s>=e)continue;
				while(k<l2.size()&&l2.get(k)[3]>=l1.get(j)[1]) {
					if(l2.get(k)[1]<=l1.get(i)[1]) {
						insert(root,-5005,5005,l2.get(k)[0]);
					}
					k++;
				}
				long v=query(root,-5005,5005,s,e);
				ret+=v*(v-1)/2;
			}
		}
		out.println(ret);
	}

	private long query(Node node, int l, int r, int s, int e) {
		if(s<=l&&r<=e) {
			return node.sum;
		}
		int m=l+(r-l)/2;
		int ret=0;
		if(m>=s) {
			ret+=query(getLnode(node),l,m,s,e);
		}
		if(m+1<=e) {
			ret+=query(getRnode(node),m+1,r,s,e);
		}
		return ret;
	}
	private void insert(Node node,int l,int r,int idx) {
		if(l==r) {
			node.sum++;
			return;
		}
		Node lnode=getLnode(node);
		Node rnode=getRnode(node);
		int m=l+(r-l)/2;
		if(idx<=m) {
			insert(lnode,l,m,idx);
		}else {
			insert(rnode,m+1,r,idx);
		}
		node.sum=lnode.sum+rnode.sum;
	}
	private Node getLnode(Node node) {
		if(node.lnode==null)node.lnode=new Node();
		return node.lnode;
	}
	private Node getRnode(Node node) {
		if(node.rnode==null)node.rnode=new Node();
		return node.rnode;
	}
	class Node{
		Node lnode,rnode;
		long sum;
	}

	//input
	private ArrayList<Integer>[] ng(int n, int m) {
		ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			int s=in.nextInt()-1,e=in.nextInt()-1;
			graph[s].add(e);
			graph[e].add(s);
			degree[s]++;
			degree[e]++;
		}
		return graph;
	}

	private ArrayList<long[]>[] ngw(int n, int m) {
		ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i]=new ArrayList<>();
		}
		for(int i=1;i<=m;i++) {
			long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
			graph[(int)s].add(new long[] {e,w});
			graph[(int)e].add(new long[] {s,w});
		}
		return graph;
	}

	private int ni() {
		return in.nextInt();
	}

	private long nl() {
		return in.nextLong();
	}

	private long[] na(int n) {
		long[] A=new long[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextLong();
		}
		return A;
	}
	private int[] nia(int n) {
		int[] A=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=in.nextInt();
		}
		return A;
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}

	public String next()
	{
		while(st==null || !st.hasMoreElements())//回车，空行情况
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	public int nextInt()
	{
		return Integer.parseInt(next());
	}

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		ArrayList<Q> al = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int x1 = f.nextInt()+5000;
			int y1 = f.nextInt()+5000;
			int x2 = f.nextInt()+5000;
			int y2 = f.nextInt()+5000;
			if(y1 == y2) al.add(new Q(x1, x2, y1, 2*i));
			else {
				al.add(new Q(x1, y1, y1 < y2, 2*i+1));
				al.add(new Q(x1, y2, y2 < y1, 2*i+1));
			}
		}
		Collections.sort(al);
		long ans = 0;
		for(int i = 0; i < al.size(); i++) {
			if(!al.get(i).q) continue;
			int l = al.get(i).x1;
			int r = al.get(i).x2;
			BIT b = new BIT(10000);
			HashSet<Integer> hs = new HashSet<>();
			for(int j = 0; j < al.size(); j++) {
				Q q = al.get(j);
				if(q.q) {
					if(j <= i) continue;
					long v = b.get(q.x2 + 1) - b.get(q.x1);
					ans += v * (v-1)/2;
				} else {
					if(q.x1 < l || q.x1 > r) continue;
					if(q.add && j < i) {
						b.add(q.x1, 1);
						hs.add(q.i);
					}
					else
						if(hs.remove(q.i)) b.add(q.x1, -1);
				}
			}
		}
		out.println(ans);
///
		out.flush();
	}
	 class BIT {
		 int[] arr;
		 public BIT(int sz) {
			 arr = new int[sz+5];
		 }
		 public int get(int i) {
			 i++;
			 int res = 0;
			 while(i > 0) {
				 res += arr[i];
				 i -= i & -i;
			 }
			 return res;
		 }
		 public void add(int i, int v) {
			 i++;
			 while(i < arr.length) {
				 arr[i]+=v;
				 i += i & -i;
			 }
		 }
	 }
	 class Q implements Comparable<Q> {
		 int x1, x2, y, i;
		 boolean q; boolean add;
		 public Q(int x1, int x2, int y, int i) {
			 this.i = i;
			 if(x2 < x1) {
				 x1 ^= x2;
				 x2 ^= x1;
				 x1 ^= x2;
			 }
			 this.x1 = x1;
			 this.x2 = x2;
			 this.y = y;
			 q = true;
		 }
		 public Q(int x, int y, boolean add, int i) {
			 this.i = i;
			 this.x1 = x;
			 this.y = y;
			 this.add = add;
		 }
		 public int compareTo(Q q) {
			 if(y != q.y) return Integer.compare(y, q.y);
			 int a = 1;
			 if(!this.q) {
				 a = 2;
				 if(add) a = 0;
			 }
			 int b = 1;
			 if(!q.q) {
				 b = 2;
				 if(q.add) b = 0;
			 }
			 return Integer.compare(a, b);
		 }
	 }
///
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		ArrayList<Q> al = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int x1 = f.nextInt()+5000;
			int y1 = f.nextInt()+5000;
			int x2 = f.nextInt()+5000;
			int y2 = f.nextInt()+5000;
			if(y1 == y2) al.add(new Q(x1, x2, y1, i));
			else {
				al.add(new Q(x1, y1, y1 < y2, i));
				al.add(new Q(x1, y2, y2 < y1, i));
			}
		}
		Collections.sort(al);
		long ans = 0;
		for(int i = 0; i < al.size(); i++) {
			if(!al.get(i).q) continue;
			int l = al.get(i).x1;
			int r = al.get(i).x2;
			BIT b = new BIT(10000);
			HashSet<Integer> hs = new HashSet<>();
			for(int j = 0; j < al.size(); j++) {
				Q q = al.get(j);
				if(q.q) {
					if(j <= i) continue;
					long v = b.get(q.x2) - b.get(q.x1-1);
					ans += v * (v-1)/2;
				} else {
					if(q.x1 < l || q.x1 > r) continue;
					if(q.add && j < i) {
						b.add(q.x1, 1);
						hs.add(q.i);
					}
					else
						if(hs.remove(q.i)) b.add(q.x1, -1);
				}
			}
		}
		out.println(ans);
///
		out.flush();
	}
	 class BIT {
		 int[] arr;
		 public BIT(int sz) {
			 arr = new int[sz+5];
		 }
		 public int get(int i) {
			 i++;
			 int res = 0;
			 while(i > 0) {
				 res += arr[i];
				 i -= i & -i;
			 }
			 return res;
		 }
		 public void add(int i, int v) {
			 i++;
			 while(i < arr.length) {
				 arr[i]+=v;
				 i += i & -i;
			 }
		 }
	 }
	 class Q implements Comparable<Q> {
		 int x1, x2, y, i;
		 boolean q; boolean add;
		 public Q(int x1, int x2, int y, int i) {
			 this.i = i;
			 if(x2 < x1) {
				 x1 ^= x2;
				 x2 ^= x1;
				 x1 ^= x2;
			 }
			 this.x1 = x1;
			 this.x2 = x2;
			 this.y = y;
			 q = true;
		 }
		 public Q(int x, int y, boolean add, int i) {
			 this.i = i;
			 this.x1 = x;
			 this.y = y;
			 this.add = add;
		 }
		 public int compareTo(Q q) {
			 if(y != q.y) return Integer.compare(y, q.y);
			 int a = 1;
			 if(!this.q) {
				 a = 2;
				 if(add) a = 0;
			 }
			 int b = 1;
			 if(!q.q) {
				 b = 2;
				 if(q.add) b = 0;
			 }
			 return Integer.compare(a, b);
		 }
	 }
///
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class P1194E {
    private static final int MAX = 10000;

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        ArrayList<int[]> horizontals = new ArrayList<>(n / 2);
        ArrayList<int[]> verticals = new ArrayList<>(n / 2);
        for (int i = 0; i < n; ++i) {
            int x1 = scanner.nextInt() + MAX / 2;
            int y1 = scanner.nextInt() + MAX / 2;
            int x2 = scanner.nextInt() + MAX / 2;
            int y2 = scanner.nextInt() + MAX / 2;
            if (y1 == y2)
                horizontals.add(new int[]{y1, Math.min(x1, x2), Math.max(x1, x2)});
            else
                verticals.add(new int[]{x1, Math.min(y1, y2), Math.max(y1, y2)});
        }
        verticals.sort(Comparator.comparingInt(o -> o[0]));
        horizontals.sort(Comparator.comparingInt(o -> o[2]));
        long cnt = 0;
        for (int i = 0; i < verticals.size(); ++i) {
            int[] left = verticals.get(i);
            ArrayList<int[]> intersects = new ArrayList<>(horizontals.size());
            int[] bit = new int[MAX + 1];
            for (int[] horizontal : horizontals) {
                if (intersect(horizontal, left)) {
                    intersects.add(horizontal);
                    bitUpdate(bit, horizontal[0], 1);
                }
            }
//            intersects.sort(Comparator.comparingInt(o -> o[2]));
            for (int j = i + 1, k = 0; j < verticals.size(); ++j) {
                int[] right = verticals.get(j);
                while (k < intersects.size() && intersects.get(k)[2] < right[0]) {
                    bitUpdate(bit, intersects.get(k)[0], -1);
                    ++k;
                }
                if (k == intersects.size())
                    break;
                int t = bitQuery(bit, Math.max(left[1], right[1]), Math.min(left[2], right[2]));
                cnt += t * (t - 1) / 2;
            }
        }
        writer.println(cnt);

        writer.close();
    }

    private static int bitQuery(int[] bit, int l, int r) {
        if (l >= r)
            return 0;
        return bitQuery(bit, r) - bitQuery(bit, l - 1);
    }

    private static int bitQuery(int[] bit, int x) {
        int cnt = 0;
        for (; x >= 0; x = (x & (x + 1)) - 1)
            cnt += bit[x];
        return cnt;
    }

    private static void bitUpdate(int[] bit, int x, int val) {
        for (; x <= MAX; x = x | (x + 1))
            bit[x] += val;
    }

    private static boolean intersect(int[] horizontal, int[] vertical) {
        return horizontal[0] >= vertical[1] && horizontal[0] <= vertical[2] && vertical[0] >= horizontal[1] && vertical[0] <= horizontal[2];
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class P1194E {
    private static final int MAX = 10000;

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        ArrayList<int[]> horizontals = new ArrayList<>(n / 2);
        ArrayList<int[]> verticals = new ArrayList<>(n / 2);
        for (int i = 0; i < n; ++i) {
            int x1 = scanner.nextInt() + MAX / 2;
            int y1 = scanner.nextInt() + MAX / 2;
            int x2 = scanner.nextInt() + MAX / 2;
            int y2 = scanner.nextInt() + MAX / 2;
            if (y1 == y2)
                horizontals.add(new int[]{y1, Math.min(x1, x2), Math.max(x1, x2)});
            else
                verticals.add(new int[]{x1, Math.min(y1, y2), Math.max(y1, y2)});
        }
        verticals.sort(Comparator.comparingInt(o -> o[0]));
        long cnt = 0;
        for (int i = 0; i < verticals.size(); ++i) {
            int[] left = verticals.get(i);
            ArrayList<int[]> intersects = new ArrayList<>(horizontals.size());
            int[] bit = new int[MAX + 1];
            for (int[] horizontal : horizontals) {
                if (intersect(horizontal, left)) {
                    intersects.add(horizontal);
                    bitUpdate(bit, horizontal[0], 1);
                }
            }
            intersects.sort(Comparator.comparingInt(o -> o[2]));
            for (int j = i + 1, k = 0; j < verticals.size(); ++j) {
                int[] right = verticals.get(j);
                while (k < intersects.size() && intersects.get(k)[2] < right[0]) {
                    bitUpdate(bit, intersects.get(k)[0], -1);
                    ++k;
                }
                if (k == intersects.size())
                    break;
                int t = bitQuery(bit, Math.max(left[1], right[1]), Math.min(left[2], right[2]));
                cnt += t * (t - 1) / 2;
            }
        }
        writer.println(cnt);

        writer.close();
    }

    private static int bitQuery(int[] bit, int l, int r) {
        if (l >= r)
            return 0;
        return bitQuery(bit, r) - bitQuery(bit, l - 1);
    }

    private static int bitQuery(int[] bit, int x) {
        int cnt = 0;
        for (; x >= 0; x = (x & (x + 1)) - 1)
            cnt += bit[x];
        return cnt;
    }

    private static void bitUpdate(int[] bit, int x, int val) {
        for (; x <= MAX; x = x | (x + 1))
            bit[x] += val;
    }

    private static boolean intersect(int[] horizontal, int[] vertical) {
        return horizontal[0] >= vertical[1] && horizontal[0] <= vertical[2] && vertical[0] >= horizontal[1] && vertical[0] <= horizontal[2];
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class P1194E {
    private static final int MAX = 10000;

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        ArrayList<int[]> horizontals = new ArrayList<>(n / 2);
        ArrayList<int[]> verticals = new ArrayList<>(n / 2);
        for (int i = 0; i < n; ++i) {
            int x1 = scanner.nextInt() + MAX / 2;
            int y1 = scanner.nextInt() + MAX / 2;
            int x2 = scanner.nextInt() + MAX / 2;
            int y2 = scanner.nextInt() + MAX / 2;
            if (y1 == y2)
                horizontals.add(new int[]{y1, Math.min(x1, x2), Math.max(x1, x2)});
            else
                verticals.add(new int[]{x1, Math.min(y1, y2), Math.max(y1, y2)});
        }
        verticals.sort(Comparator.comparingInt(o -> o[0]));
        long cnt = 0;
        for (int i = 0; i < verticals.size(); ++i) {
            int[] left = verticals.get(i);
            ArrayList<int[]> intersects = new ArrayList<>(horizontals.size());
            int[] bit = new int[MAX + 1];
            for (int[] horizontal : horizontals) {
                if (intersect(horizontal, left)) {
                    intersects.add(horizontal);
                    bitUpdate(bit, horizontal[0], 1);
                }
            }
            intersects.sort(Comparator.comparingInt(o -> o[2]));
            for (int j = i + 1, k = 0; j < verticals.size(); ++j) {
                int[] right = verticals.get(j);
                while (k < intersects.size() && intersects.get(k)[2] < right[0])
                    bitUpdate(bit, intersects.get(k)[0], -1);
                if (k == intersects.size())
                    break;
                int t = bitQuery(bit, Math.max(left[1], right[1]), Math.min(left[2], right[2]));
                cnt += t * (t - 1) / 2;
            }
        }
        writer.println(cnt);

        writer.close();
    }

    private static int bitQuery(int[] bit, int l, int r) {
        if (l >= r)
            return 0;
        return bitQuery(bit, r) - bitQuery(bit, l - 1);
    }

    private static int bitQuery(int[] bit, int x) {
        int cnt = 0;
        for (; x >= 0; x = (x & (x + 1)) - 1)
            cnt += bit[x];
        return cnt;
    }

    private static void bitUpdate(int[] bit, int x, int val) {
        for (; x <= MAX; x = x | (x + 1))
            bit[x] += val;
    }

    private static boolean intersect(int[] horizontal, int[] vertical) {
        return horizontal[0] >= vertical[1] && horizontal[0] <= vertical[2] && vertical[0] >= horizontal[1] && vertical[0] <= horizontal[2];
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}