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

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static long inf = (long) 1e16;
	static int[] l, r;
	static int n, m, id;
	static long all, ans;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static long[] a;
	static ArrayList<Integer> h;
	static boolean vis[];

	public static class FenwickTree { // one-based DS

		int n;
		int[] ft;

		FenwickTree(int size) {
			n = size;
			ft = new int[n + 1];
		}

		int rsq(int b) // O(log n)
		{
			int sum = 0;
			while (b > 0) {
				sum += ft[b];
				b -= b & -b;
			} // min?
			return sum;
		}

		int rsq(int a, int b) {
			return rsq(b) - rsq(a - 1);
		}

		void point_update(int k, int val) // O(log n), update = increment
		{
			while (k <= n) {
				ft[k] += val;
				k += k & -k;
			} // min?
		}
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int offset = 5001;
		n = sc.nextInt();
		int v = 0;
		int h = 0;
		int[] xs = new int[n];
		int[] ys = new int[n];
		int[] xe = new int[n];
		int[] ye = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt() + offset;
			ys[i] = sc.nextInt() + offset;
			xe[i] = sc.nextInt() + offset;
			ye[i] = sc.nextInt() + offset;
			if (xs[i] == xe[i]) {
				int min = Math.min(ys[i], ye[i]);
				int max = Math.max(ys[i], ye[i]);
				ys[i] = min;
				ye[i] = max;
				v++;
			} else {
				int min = Math.min(xs[i], xe[i]);
				int max = Math.max(xs[i], xe[i]);
				xs[i] = min;
				xe[i] = max;
				h++;
			}
		}
		long ans = 0;
		tri[] V = new tri[v];
		tri[] H = new tri[h];
		int iv = 0;
		int ih = 0;
		for (int i = 0; i < n; i++) {
			if (xs[i] == xe[i]) {
				V[iv++] = new tri(xs[i], ys[i], ye[i]);
			} else {
				H[ih++] = new tri(ys[i], xs[i], xe[i]);
			}
		}
		Arrays.sort(V);
		FenwickTree ft = new FenwickTree(10001);
		for (int i = 0; i < v; i++) {
			int interlinked = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					interlinked++;
				}
			}
			tri[] ar = new tri[interlinked];
			int id = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					ar[id++] = new tri(H[inter].ed - V[i].d, H[inter].d, 0);
					ft.point_update(H[inter].d, 1);
				}
			}
			Arrays.sort(ar);
			id = 0;
			for (int j = i + 1; j < v; j++) {
				if (V[i].d == V[j].d)
					continue;
				while (id < interlinked && ar[id].d < V[j].d - V[i].d) {
					ft.point_update(ar[id].st, -1);
					id++;
				}
				long x = ft.rsq(V[j].st, V[j].ed);
				ans += x * (x - 1) / 2;
			}
			while (id < interlinked) {
				ft.point_update(ar[id].st, -1);
				id++;
			}
		}
		System.out.println(ans);
		out.flush();
	}

	static class tri implements Comparable<tri> {
		int d, st, ed;

		tri(int d, int s, int e) {
			this.d = d;
			st = s;
			ed = e;
		}

		public String toString() {
			return d + " " + st + " " + ed;
		}

		@Override
		public int compareTo(tri o) {
			return d - o.d;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


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

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static long inf = (long) 1e16;
	static int[] l, r;
	static int n, m, id;
	static long all, ans;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static long[] a;
	static ArrayList<Integer> h;
	static boolean vis[];

	public static class FenwickTree { // one-based DS

		int n;
		int[] ft;

		FenwickTree(int size) {
			n = size;
			ft = new int[n + 1];
		}

		int rsq(int b) // O(log n)
		{
			int sum = 0;
			while (b > 0) {
				sum += ft[b];
				b -= b & -b;
			} // min?
			return sum;
		}

		int rsq(int a, int b) {
			return rsq(b) - rsq(a - 1);
		}

		void point_update(int k, int val) // O(log n), update = increment
		{
			while (k <= n) {
				ft[k] += val;
				k += k & -k;
			} // min?
		}
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int offset = 5001;
		n = sc.nextInt();
		int v = 0;
		int h = 0;
		int[] xs = new int[n];
		int[] ys = new int[n];
		int[] xe = new int[n];
		int[] ye = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt() + offset;
			ys[i] = sc.nextInt() + offset;
			xe[i] = sc.nextInt() + offset;
			ye[i] = sc.nextInt() + offset;
			if (xs[i] == xe[i]) {
				int min = Math.min(ys[i], ye[i]);
				int max = Math.max(ys[i], ye[i]);
				ys[i] = min;
				ye[i] = max;
				v++;
			} else {
				int min = Math.min(xs[i], xe[i]);
				int max = Math.max(xs[i], xe[i]);
				xs[i] = min;
				xe[i] = max;
				h++;
			}
		}
		long ans = 0;
		tri[] V = new tri[v];
		tri[] H = new tri[h];
		int iv = 0;
		int ih = 0;
		for (int i = 0; i < n; i++) {
			if (xs[i] == xe[i]) {
				V[iv++] = new tri(xs[i], ys[i], ye[i]);
			} else {
				H[ih++] = new tri(ys[i], xs[i], xe[i]);
			}
		}
		Arrays.sort(V);
		// SegmentTree st = new SegmentTree(new int[16385]);
		FenwickTree ft = new FenwickTree(10001);
		for (int i = 0; i < v; i++) {
			int interlinked = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					interlinked++;
				}
			}
			tri[] ar = new tri[interlinked];
			int id = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					ar[id++] = new tri(H[inter].ed - V[i].d, H[inter].d, 0);
				}
			}
			Arrays.sort(ar);
			for (int j = 0; j < interlinked; j++)
				ft.point_update(H[j].d, 1);
			id = 0;
			for (int j = i + 1; j < v; j++) {
				if (V[i].d == V[j].d)
					continue;
				while (id < interlinked && ar[id].d < V[j].d - V[i].d) {
					ft.point_update(ar[id].st, -1);
					id++;
				}
				long x = ft.rsq(V[j].st, V[j].ed);
				ans += x * (x - 1) / 2;
			}
			while (id < interlinked) {
				ft.point_update(ar[id].st, -1);
				id++;
			}
		}
		System.out.println(ans);
		out.flush();
	}

	public static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;

		}

	}

	static class tri implements Comparable<tri> {
		int d, st, ed;

		tri(int d, int s, int e) {
			this.d = d;
			st = s;
			ed = e;
		}

		public String toString() {
			return d + " " + st + " " + ed;
		}

		@Override
		public int compareTo(tri o) {
			return d - o.d;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


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

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static long inf = (long) 1e16;
	static int[] l, r;
	static int n, m, id;
	static long all, ans;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static long[] a;
	static ArrayList<Integer> h;
	static boolean vis[];

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int offset = 5001;
		n = sc.nextInt();
		int v = 0;
		int h = 0;
		int[] xs = new int[n];
		int[] ys = new int[n];
		int[] xe = new int[n];
		int[] ye = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt() + offset;
			ys[i] = sc.nextInt() + offset;
			xe[i] = sc.nextInt() + offset;
			ye[i] = sc.nextInt() + offset;
			if (xs[i] == xe[i]) {
				int min = Math.min(ys[i], ye[i]);
				int max = Math.max(ys[i], ye[i]);
				ys[i] = min;
				ye[i] = max;
				v++;
			} else {
				int min = Math.min(xs[i], xe[i]);
				int max = Math.max(xs[i], xe[i]);
				xs[i] = min;
				xe[i] = max;
				h++;
			}
		}
		long ans = 0;
		tri[] V = new tri[v];
		tri[] H = new tri[h];
		int iv = 0;
		int ih = 0;
		for (int i = 0; i < n; i++) {
			if (xs[i] == xe[i]) {
				V[iv++] = new tri(xs[i], ys[i], ye[i]);
			} else {
				H[ih++] = new tri(ys[i], xs[i], xe[i]);
			}
		}
		Arrays.sort(V);
	//	System.out.println(Arrays.toString(V));
	//	System.out.println(Arrays.toString(H));
		for (int i = 0; i < v; i++) {
			SegmentTree st = new SegmentTree(new int[16385]);
			int interlinked = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					interlinked++;
				}
			}
			tri[] ar = new tri[interlinked];
			int id = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					ar[id++] = new tri(H[inter].ed - V[i].d, H[inter].d, 0);
					st.update_point(H[inter].d, 1);
				}
			}
			Arrays.sort(ar);
			id = 0;
			for (int j = i + 1; j < v; j++) {
				while (id < interlinked && ar[id].d < V[j].d - V[i].d) {
					st.update_point(ar[id].st, -1);
					id++;
				}
				long x = st.query(V[j].st, V[j].ed);
				ans += x * (x - 1) / 2;
			}
		}
		System.out.println(ans);
		out.flush();
	}

	public static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;

		}

	}

	static class tri implements Comparable<tri> {
		int d, st, ed;

		tri(int d, int s, int e) {
			this.d = d;
			st = s;
			ed = e;
		}

		public String toString() {
			return d + " " + st + " " + ed;
		}

		@Override
		public int compareTo(tri o) {
			return d - o.d;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


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

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 998244353;
	static long inf = (long) 1e16;
	static int[] l, r;
	static int n, m, id;
	static long all, ans;
	static ArrayList<Integer>[] ad;
	static long[][][] memo;
	static long[] a;
	static ArrayList<Integer> h;
	static boolean vis[];

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int offset = 5001;
		n = sc.nextInt();
		int v = 0;
		int h = 0;
		int[] xs = new int[n];
		int[] ys = new int[n];
		int[] xe = new int[n];
		int[] ye = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt() + offset;
			ys[i] = sc.nextInt() + offset;
			xe[i] = sc.nextInt() + offset;
			ye[i] = sc.nextInt() + offset;
			if (xs[i] == xe[i]) {
				int min = Math.min(ys[i], ye[i]);
				int max = Math.max(ys[i], ye[i]);
				ys[i] = min;
				ye[i] = max;
				v++;
			} else {
				int min = Math.min(xs[i], xe[i]);
				int max = Math.max(xs[i], xe[i]);
				xs[i] = min;
				xe[i] = max;
				h++;
			}
		}
		long ans = 0;
		tri[] V = new tri[v];
		tri[] H = new tri[h];
		int iv = 0;
		int ih = 0;
		for (int i = 0; i < n; i++) {
			if (xs[i] == xe[i]) {
				V[iv++] = new tri(xs[i], ys[i], ye[i]);
			} else {
				H[ih++] = new tri(ys[i], xs[i], xe[i]);
			}
		}
		Arrays.sort(V);
		// System.out.println(Arrays.toString(V));
		// System.out.println(Arrays.toString(H));
		SegmentTree st = new SegmentTree(new int[16385]);
		for (int i = 0; i < v; i++) {
			int interlinked = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					interlinked++;
				}
			}
			tri[] ar = new tri[interlinked];
			int id = 0;
			for (int inter = 0; inter < h; inter++) {
				if (H[inter].d >= V[i].st && H[inter].d <= V[i].ed && V[i].d >= H[inter].st && V[i].d <= H[inter].ed) {
					ar[id++] = new tri(H[inter].ed - V[i].d, H[inter].d, 0);
					// st.update_point(H[inter].d, 1);
				}
			}
			Arrays.sort(ar);
			for (int j = 0; j < interlinked; j++)
				st.update_point(H[j].d, 1);
			id = 0;
			for (int j = i + 1; j < v; j++) {
				while (id < interlinked && ar[id].d < V[j].d - V[i].d) {
					st.update_point(ar[id].st, -1);
					id++;
				}
				long x = st.query(V[j].st, V[j].ed);
				ans += x * (x - 1) / 2;
			}
			while (id < interlinked) {
				st.update_point(ar[id].st, -1);
				id++;
			}
		}
		System.out.println(ans);
		out.flush();
	}

	public static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return q1 + q2;

		}

	}

	static class tri implements Comparable<tri> {
		int d, st, ed;

		tri(int d, int s, int e) {
			this.d = d;
			st = s;
			ed = e;
		}

		public String toString() {
			return d + " " + st + " " + ed;
		}

		@Override
		public int compareTo(tri o) {
			return d - o.d;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        static final int MAX = 5000;
        static final int SIZE = MAX * 2 + 1;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            List<ECountTheRectangles.Item> items = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items.add(new ECountTheRectangles.Item(x1, yl, yh));
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items.add(new ECountTheRectangles.Item(xl, y1, true));
                    items.add(new ECountTheRectangles.Item(xh, y1, false));
                }
            }

            items.sort(Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            int answer = 0;
            for (int i = 0; i < items.size(); i++) {
                ECountTheRectangles.Item item = items.get(i);
                if (!item.isPoint) {
                    answer += count(items, i);
                }
            }

            out.println(answer);
        }

        private int count(List<ECountTheRectangles.Item> items, int start) {
            IntSegmentTree tree = new IntSegmentTree(SIZE, Integer::sum, 0);
            ECountTheRectangles.Item left = items.get(start);
            int result = 0;
            for (int i = 0; i < items.size(); i++) {
                ECountTheRectangles.Item item = items.get(i);
                if (item.isPoint) {
                    if (item.start && i < start || !item.start && i > start)
                        if (item.y >= left.y && item.y <= left.y2)
                            tree.update(item.y, item.start ? 1 : 0);
                } else {
                    if (i > start) {
                        result += nc2(tree.query(item.y, item.y2 + 1));
                    }
                }
            }

            return result;
        }

        private static int nc2(int n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            public Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            public Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class IntSegmentTree {
        public int size;
        public int[] value;
        protected final IntSegmentTree.Combiner combiner;
        protected final int identityElement;

        public IntSegmentTree(int size, IntSegmentTree.Combiner combiner, int identityElement) {
            this.size = size;
            value = new int[2 * size];
            Arrays.fill(value, identityElement);
            this.combiner = combiner;
            this.identityElement = identityElement;
        }

        protected int combine(int a, int b) {
            return combiner.combine(a, b);
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

        public interface Combiner {
            int combine(int a, int b);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        private static final int MAX = 5000;
        private static final int SIZE = MAX * 2 + 1;
        ECountTheRectangles.Item[] items;
        int itemCount = 0;
        IntSegmentTree tree;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            items = new ECountTheRectangles.Item[2 * n];
            itemCount = 0;
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items[itemCount++] = new ECountTheRectangles.Item(x1, yl, yh);
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items[itemCount++] = new ECountTheRectangles.Item(xl, y1, true);
                    items[itemCount++] = new ECountTheRectangles.Item(xh, y1, false);
                }
            }

            Arrays.sort(items, 0, itemCount, Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            tree = new IntSegmentTree(SIZE, Integer::sum, 0);
            for (int i = 0; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (!item.isPoint) {
                    answer += count(i);
                }
            }

            out.println(answer);
        }

        private long count(int start) {
            ECountTheRectangles.Item left = items[start];
            long result = 0;
            for (int i = 0; i < start; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (item.y >= left.y && item.y <= left.y2) {
                        if (item.start)
                            tree.update_LAZY(item.y, 1);
                        else
                            tree.update_LAZY(item.y, 0);
                    }
                }
            }

            tree.rebuild();

            for (int i = start + 1; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (!item.start && item.y >= left.y && item.y <= left.y2) {
                        if (tree.get(item.y) == 1)
                            tree.update(item.y, 0);
                    }
                } else {
                    int yl = Math.max(left.y, item.y);
                    int yh = Math.min(left.y2, item.y2);

                    result += nc2(tree.query(yl, yh + 1));
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class IntSegmentTree {
        public int size;
        public int[] value;
        protected final IntSegmentTree.Combiner combiner;
        protected final int identityElement;

        public IntSegmentTree(int size, IntSegmentTree.Combiner combiner, int identityElement) {
            this.size = size;
            value = new int[2 * size];
            Arrays.fill(value, identityElement);
            this.combiner = combiner;
            this.identityElement = identityElement;
        }

        protected int combine(int a, int b) {
            return combiner.combine(a, b);
        }

        public void rebuild() {
            for (int i = size - 1; i > 0; i--) {
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int get(int i) {
            return value[size + i];
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public void update_LAZY(int i, int v) {
            i += size;
            value[i] = v;
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

        public interface Combiner {
            int combine(int a, int b);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        static final int MAX = 5000;
        static final int SIZE = MAX * 2 + 1;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            List<ECountTheRectangles.Item> items = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items.add(new ECountTheRectangles.Item(x1, yl, yh));
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items.add(new ECountTheRectangles.Item(xl, y1, true));
                    items.add(new ECountTheRectangles.Item(xh, y1, false));
                }
            }

            items.sort(Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            for (int i = 0; i < items.size(); i++) {
                IntSegmentTree tree = new IntSegmentTree(SIZE, Integer::sum, 0);
                ECountTheRectangles.Item item = items.get(i);
                if (!item.isPoint) {
                    answer += count(items, i, tree);
                }
            }

            out.println(answer);
        }

        private long count(List<ECountTheRectangles.Item> items, int start, IntSegmentTree tree) {
            ECountTheRectangles.Item left = items.get(start);
            long result = 0;
            for (int i = 0; i < items.size(); i++) {
                ECountTheRectangles.Item item = items.get(i);
                if (item.isPoint) {
                    if (item.start && i < start || !item.start)
                        if (item.y >= left.y && item.y <= left.y2)
                            tree.update(item.y, item.start ? 1 : 0);
                } else {
                    if (i > start) {
                        result += nc2(tree.query(item.y, item.y2 + 1));
                    }
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            public Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            public Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class IntSegmentTree {
        public int size;
        public int[] value;
        protected final IntSegmentTree.Combiner combiner;
        protected final int identityElement;

        public IntSegmentTree(int size, IntSegmentTree.Combiner combiner, int identityElement) {
            this.size = size;
            value = new int[2 * size];
            Arrays.fill(value, identityElement);
            this.combiner = combiner;
            this.identityElement = identityElement;
        }

        protected int combine(int a, int b) {
            return combiner.combine(a, b);
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

        public interface Combiner {
            int combine(int a, int b);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        private static final int MAX = 5000;
        private static final int SIZE = MAX * 2 + 1;
        ECountTheRectangles.Item[] items;
        int itemCount = 0;
        IntSumSegmentTree tree;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            items = new ECountTheRectangles.Item[2 * n];
            itemCount = 0;
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items[itemCount++] = new ECountTheRectangles.Item(x1, yl, yh);
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items[itemCount++] = new ECountTheRectangles.Item(xl, y1, true);
                    items[itemCount++] = new ECountTheRectangles.Item(xh, y1, false);
                }
            }

            Arrays.sort(items, 0, itemCount, Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            tree = new IntSumSegmentTree(SIZE);
            for (int i = 0; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (!item.isPoint) {
                    answer += count(i);
                }
            }

            out.println(answer);
        }

        private long count(int start) {
            ECountTheRectangles.Item left = items[start];
            long result = 0;
            for (int i = 0; i < start; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (item.y >= left.y && item.y <= left.y2) {
                        if (item.start)
                            tree.update_LAZY(item.y, 1);
                        else
                            tree.update_LAZY(item.y, 0);
                    }
                }
            }

            tree.rebuild();

            for (int i = start + 1; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (!item.start && item.y >= left.y && item.y <= left.y2) {
                        if (tree.get(item.y) == 1)
                            tree.update(item.y, 0);
                    }
                } else {
                    int yl = Math.max(left.y, item.y);
                    int yh = Math.min(left.y2, item.y2);

                    result += nc2(tree.query(yl, yh + 1));
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }

    static class IntSumSegmentTree {
        public int size;
        public int[] value;

        public IntSumSegmentTree(int size) {
            this.size = size;
            value = new int[2 * size];
        }

        public void rebuild() {
            for (int i = size - 1; i > 0; i--) {
                value[i] = value[2 * i] + value[2 * i + 1];
            }
        }

        public int get(int i) {
            return value[size + i];
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = value[2 * i] + value[2 * i + 1];
            }
        }

        public void update_LAZY(int i, int v) {
            i += size;
            value[i] = v;
        }

        public int query(int i, int j) {
            int res_left = 0, res_right = 0;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1) {
                    int b = value[i++];
                    res_left = res_left + b;
                }
                if ((j & 1) == 1) {
                    int a = value[--j];
                    res_right = a + res_right;
                }
            }
            return res_left + res_right;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        private static final int MAX = 5000;
        private static final int SIZE = MAX * 2 + 1;
        ECountTheRectangles.Item[] items;
        int itemCount = 0;
        IntSegmentTree tree;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            items = new ECountTheRectangles.Item[2 * n];
            itemCount = 0;
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items[itemCount++] = new ECountTheRectangles.Item(x1, yl, yh);
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items[itemCount++] = new ECountTheRectangles.Item(xl, y1, true);
                    items[itemCount++] = new ECountTheRectangles.Item(xh, y1, false);
                }
            }

            Arrays.sort(items, 0, itemCount, Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            for (int i = 0; i < itemCount; i++) {
                tree = new IntSegmentTree(SIZE, Integer::sum, 0);
                ECountTheRectangles.Item item = items[i];
                if (!item.isPoint) {
                    answer += count(i);
                }
            }

            out.println(answer);
        }

        private long count(int start) {
            ECountTheRectangles.Item left = items[start];
            long result = 0;
            for (int i = 0; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (!item.start || i < start)
                        if (item.y >= left.y && item.y <= left.y2)
                            tree.update(item.y, item.start ? 1 : 0);
                } else {
                    if (i > start) {
                        result += nc2(tree.query(item.y, item.y2 + 1));
                    }
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class IntSegmentTree {
        public int size;
        public int[] value;
        protected final IntSegmentTree.Combiner combiner;
        protected final int identityElement;

        public IntSegmentTree(int size, IntSegmentTree.Combiner combiner, int identityElement) {
            this.size = size;
            value = new int[2 * size];
            Arrays.fill(value, identityElement);
            this.combiner = combiner;
            this.identityElement = identityElement;
        }

        protected int combine(int a, int b) {
            return combiner.combine(a, b);
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

        public interface Combiner {
            int combine(int a, int b);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        private static final int MAX = 5000;
        private static final int SIZE = MAX * 2 + 1;
        ECountTheRectangles.Item[] items;
        int itemCount = 0;
        IntSegmentTree tree;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            items = new ECountTheRectangles.Item[2 * n];
            itemCount = 0;
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items[itemCount++] = new ECountTheRectangles.Item(x1, yl, yh);
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items[itemCount++] = new ECountTheRectangles.Item(xl, y1, true);
                    items[itemCount++] = new ECountTheRectangles.Item(xh, y1, false);
                }
            }

            Arrays.sort(items, 0, itemCount, Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            tree = new IntSegmentTree(SIZE, Integer::sum, 0);
            for (int i = 0; i < itemCount; i++) {
                if (!items[i].isPoint) {
                    answer += count(i);
                }
            }

            out.println(answer);
        }

        private long count(int start) {
            ECountTheRectangles.Item left = items[start];
            long result = 0;
            for (int i = 0; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (!item.start || i < start)
                        if (item.y >= left.y && item.y <= left.y2) {
                            if (item.start)
                                tree.update(item.y, 1);
                            else if (tree.get(item.y) == 1)
                                tree.update(item.y, 0);
                        }
                } else {
                    if (i > start) {
                        int yl = Math.max(left.y, item.y);
                        int yh = Math.min(left.y2, item.y2);

                        int tot = tree.query(yl, yh + 1);
                        result += nc2(tot);
                    }
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class IntSegmentTree {
        public int size;
        public int[] value;
        protected final IntSegmentTree.Combiner combiner;
        protected final int identityElement;

        public IntSegmentTree(int size, IntSegmentTree.Combiner combiner, int identityElement) {
            this.size = size;
            value = new int[2 * size];
            Arrays.fill(value, identityElement);
            this.combiner = combiner;
            this.identityElement = identityElement;
        }

        protected int combine(int a, int b) {
            return combiner.combine(a, b);
        }

        public int get(int i) {
            return value[size + i];
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

        public interface Combiner {
            int combine(int a, int b);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class ECountTheRectangles {
        private static final int MAX = 5000;
        private static final int SIZE = MAX * 2 + 1;
        ECountTheRectangles.Item[] items;
        int itemCount = 0;
        IntSumSegmentTree tree;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            items = new ECountTheRectangles.Item[2 * n];
            itemCount = 0;
            for (int i = 0; i < n; i++) {
                int x1 = MAX + in.nextInt();
                int y1 = MAX + in.nextInt();
                int x2 = MAX + in.nextInt();
                int y2 = MAX + in.nextInt();

                if (x1 == x2) {
                    int yl = Math.min(y1, y2);
                    int yh = Math.max(y1, y2);
                    items[itemCount++] = new ECountTheRectangles.Item(x1, yl, yh);
                } else {
                    int xl = Math.min(x1, x2);
                    int xh = Math.max(x1, x2);
                    items[itemCount++] = new ECountTheRectangles.Item(xl, y1, true);
                    items[itemCount++] = new ECountTheRectangles.Item(xh, y1, false);
                }
            }

            Arrays.sort(items, 0, itemCount, Comparator.comparingInt((ECountTheRectangles.Item i) -> i.x).thenComparingInt(i -> {
                if (!i.isPoint)
                    return 0;
                return i.start ? -1 : 1;
            }));

            long answer = 0;
            tree = new IntSumSegmentTree(SIZE);
            for (int i = 0; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (!item.isPoint) {
                    answer += count(i);
                }
            }

            out.println(answer);
        }

        private long count(int start) {
            ECountTheRectangles.Item left = items[start];
            long result = 0;
            for (int i = 0; i < start; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (item.y >= left.y && item.y <= left.y2) {
                        if (item.start)
                            tree.update_LAZY(item.y, 1);
                        else
                            tree.update_LAZY(item.y, 0);
                    }
                }
            }

            tree.rebuild();

            for (int i = start + 1; i < itemCount; i++) {
                ECountTheRectangles.Item item = items[i];
                if (item.isPoint) {
                    if (!item.start && item.y >= left.y && item.y <= left.y2) {
                        if (tree.get(item.y) == 1)
                            tree.update(item.y, 0);
                    }
                } else {
                    int yl = Math.max(left.y, item.y);
                    int yh = Math.min(left.y2, item.y2);

                    result += nc2(tree.query(yl, yh + 1));
                }
            }

            return result;
        }

        private static long nc2(long n) {
            return n * (n - 1) / 2;
        }

        private static class Item {
            int x;
            int y;
            int y2;
            boolean isPoint;
            boolean start;

            Item(int x, int y1, int y2) {
                this.x = x;
                this.y = y1;
                this.y2 = y2;
                isPoint = false;
            }

            Item(int x, int y, boolean start) {
                this.x = x;
                this.y = y;
                isPoint = true;
                this.start = start;
            }

            public String toString() {
                return String.format("(%d, %d, %d, %s, %s)", x - MAX, y - MAX, y2 - MAX, isPoint ? "P" : "L", start ? "S" : "E");
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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());
        }

    }

    static class IntSumSegmentTree {
        public int size;
        public int[] value;
        protected final int identityElement = 0;

        public IntSumSegmentTree(int size) {
            this.size = size;
            value = new int[2 * size];
        }

        private int combine(int a, int b) {
            return a + b;
        }

        public void rebuild() {
            for (int i = size - 1; i > 0; i--) {
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public int get(int i) {
            return value[size + i];
        }

        public void update(int i, int v) {
            i += size;
            value[i] = v;
            while (i > 1) {
                i /= 2;
                value[i] = combine(value[2 * i], value[2 * i + 1]);
            }
        }

        public void update_LAZY(int i, int v) {
            i += size;
            value[i] = v;
        }

        public int query(int i, int j) {
            int res_left = identityElement, res_right = identityElement;
            for (i += size, j += size; i < j; i /= 2, j /= 2) {
                if ((i & 1) == 1)
                    res_left = combine(res_left, value[i++]);
                if ((j & 1) == 1)
                    res_right = combine(value[--j], res_right);
            }
            return combine(res_left, res_right);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskE {
        final int shift = 5001;
        final int max = shift * 2;
        int[] tree;

        void update(int id, int value) {
            while (id < max) {
                tree[id] += value;
                id += (id & (-id));
            }
        }

        int read(int id) {
            int res = 0;
            while (id > 0) {
                res += tree[id];
                id -= (id & (-id));
            }
            return res;
        }

        int range(int a, int b) {
            return read(b) - read(a - 1);
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Horizontal>[] horizonal = new ArrayList[max];
            ArrayList<Vertical>[] vertical = new ArrayList[max];
            for (int i = 0; i < max; i++) {
                horizonal[i] = new ArrayList<>();
                vertical[i] = new ArrayList<>();
            }

            for (int i = 0; i < n; i++) {
                int x1 = in.nextInt() + shift;
                int y1 = in.nextInt() + shift;
                int x2 = in.nextInt() + shift;
                int y2 = in.nextInt() + shift;
                if (x1 == x2) {
                    vertical[x1].add(new Vertical(Math.min(y1, y2), Math.max(y1, y2)));
                } else {
                    horizonal[y1].add(new Horizontal(Math.min(x1, x2), Math.max(x1, x2)));
                }
            }

            long ans = 0;
            ArrayList<Integer>[] delete = new ArrayList[max];
            for (int i = 0; i < max; i++) {
                delete[i] = new ArrayList<>();
            }
            for (int y = 0; y < max; y++) {
                for (Horizontal h : horizonal[y]) {
                    tree = new int[max];

                    int xLeft = h.x1;
                    int xRight = h.x2;
                    for (int x = xLeft; x <= xRight; x++) {
                        for (Vertical v : vertical[x]) {
                            if (v.y1 <= y && y < v.y2) {
                                update(x, +1);
                                delete[v.y2].add(x);
                            }
                        }
                    }

                    for (int y2 = y + 1; y2 < max; y2++) {
                        for (Horizontal h2 : horizonal[y2]) {
                            long cnt = range(h2.x1, h2.x2);
                            ans += ((cnt * (cnt - 1)) >> 1);
                        }
                        for (int x : delete[y2])
                            update(x, -1);
                        delete[y2].clear();
                    }
                }
            }
            out.println(ans);
            return;
        }

        class Horizontal {
            int x1;
            int x2;

            Horizontal(int x1, int x2) {
                this.x1 = x1;
                this.x2 = x2;
            }

        }

        class Vertical {
            int y1;
            int y2;

            Vertical(int y1, int y2) {
                this.y1 = y1;
                this.y2 = y2;
            }

        }

    }

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

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

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

        private 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 nextInt() {
            int c = read();
            while (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskE {
        final int shift = 5001;
        final int max = shift * 2;
        int[] tree;

        void update(int id, int value) {
            while (id < max) {
                tree[id] += value;
                id += (id & (-id));
            }
        }

        int read(int id) {
            int res = 0;
            while (id > 0) {
                res += tree[id];
                id -= (id & (-id));
            }
            return res;
        }

        int range(int a, int b) {
            return read(b) - read(a - 1);
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Horizontal>[] horizonal = new ArrayList[max];
            ArrayList<Vertical>[] vertical = new ArrayList[max];
            for (int i = 0; i < max; i++) {
                horizonal[i] = new ArrayList<>();
                vertical[i] = new ArrayList<>();
            }

            for (int i = 0; i < n; i++) {
                int x1 = in.nextInt() + shift;
                int y1 = in.nextInt() + shift;
                int x2 = in.nextInt() + shift;
                int y2 = in.nextInt() + shift;
                if (x1 == x2) {
                    vertical[x1].add(new Vertical(Math.min(y1, y2), Math.max(y1, y2)));
                } else {
                    horizonal[y1].add(new Horizontal(Math.min(x1, x2), Math.max(x1, x2)));
                }
            }

            long ans = 0;
            ArrayList<Integer>[] delete = new ArrayList[max];
            for (int i = 0; i < max; i++) {
                delete[i] = new ArrayList<>();
            }
            tree = new int[max];
            for (int y = 0; y < max; y++) {
                for (Horizontal h : horizonal[y]) {

                    int xLeft = h.x1;
                    int xRight = h.x2;
                    for (int x = xLeft; x <= xRight; x++) {
                        for (Vertical v : vertical[x]) {
                            if (v.y1 <= y && y < v.y2) {
                                update(x, +1);
                                delete[v.y2].add(x);
                            }
                        }
                    }

                    for (int y2 = y + 1; y2 < max; y2++) {
                        for (Horizontal h2 : horizonal[y2]) {
                            long cnt = range(h2.x1, h2.x2);
                            ans += ((cnt * (cnt - 1)) >> 1);
                        }
                        for (int x : delete[y2])
                            update(x, -1);
                        delete[y2].clear();
                    }
                }
            }
            out.println(ans);
            return;
        }

        class Horizontal {
            int x1;
            int x2;

            Horizontal(int x1, int x2) {
                this.x1 = x1;
                this.x2 = x2;
            }

        }

        class Vertical {
            int y1;
            int y2;

            Vertical(int y1, int y2) {
                this.y1 = y1;
                this.y2 = y2;
            }

        }

    }

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

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

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

        private 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 nextInt() {
            int c = read();
            while (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

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

    static class TaskE {
        final int shift = 5001;
        final int max = shift * 2;
        int[] tree;

        void update(int id, int value) {
            while (id < max) {
                tree[id] += value;
                id += (id & (-id));
            }
        }

        int read(int id) {
            int res = 0;
            while (id > 0) {
                res += tree[id];
                id -= (id & (-id));
            }
            return res;
        }

        int range(int a, int b) {
            return read(b) - read(a - 1);
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Horizontal>[] horizonal = new ArrayList[max];
            ArrayList<Vertical>[] vertical = new ArrayList[max];
            for (int i = 0; i < max; i++) {
                horizonal[i] = new ArrayList<>();
                vertical[i] = new ArrayList<>();
            }

            for (int i = 0; i < n; i++) {
                int x1 = in.nextInt() + shift;
                int y1 = in.nextInt() + shift;
                int x2 = in.nextInt() + shift;
                int y2 = in.nextInt() + shift;
                if (x1 == x2) {
                    vertical[x1].add(new Vertical(Math.min(y1, y2), Math.max(y1, y2)));
                } else {
                    horizonal[y1].add(new Horizontal(Math.min(x1, x2), Math.max(x1, x2)));
                }
            }

            long ans = 0;
            for (int y = 0; y < max; y++) {
                for (Horizontal h : horizonal[y]) {
                    ArrayList<Integer>[] delete = new ArrayList[max];
                    for (int i = 0; i < max; i++) {
                        delete[i] = new ArrayList<>();
                    }
                    tree = new int[max];

                    int xLeft = h.x1;
                    int xRight = h.x2;
                    for (int x = xLeft; x <= xRight; x++) {
                        for (Vertical v : vertical[x]) {
                            if (v.y1 <= y && y < v.y2) {
                                update(x, +1);
                                delete[v.y2].add(x);
                            }
                        }
                    }

                    for (int y2 = y + 1; y2 < max; y2++) {
                        for (Horizontal h2 : horizonal[y2]) {
                            long cnt = range(h2.x1, h2.x2);
                            ans += ((cnt * (cnt - 1)) >> 1);
                        }
                        for (int x : delete[y2])
                            update(x, -1);
                    }
                }
            }
            out.println(ans);
            return;
        }

        class Horizontal {
            int x1;
            int x2;

            Horizontal(int x1, int x2) {
                this.x1 = x1;
                this.x2 = x2;
            }

        }

        class Vertical {
            int y1;
            int y2;

            Vertical(int y1, int y2) {
                this.y1 = y1;
                this.y2 = y2;
            }

        }

    }

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

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

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

        private 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 nextInt() {
            int c = read();
            while (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

    }
}


//package educational.round68;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;

public class E2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[][] hs = new int[n][];
		int[][] vs = new int[n][];
		int hp = 0, vp = 0;
		for(int i = 0;i < n;i++){
			int x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();
			if(y1 > y2){
				int d = y1; y1 = y2; y2 = d;
			}
			if(x1 > x2){
				int d = x1; x1 = x2; x2 = d;
			}
			if(x1 == x2){
				vs[vp++] = new int[]{x1, y1, y2, -1};
			}else{
				hs[hp++] = new int[]{y1, x1, x2};
			}
		}
		vs = Arrays.copyOf(vs, vp);
		hs = Arrays.copyOf(hs, hp);

		Arrays.sort(hs, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});

		Arrays.sort(vs, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});
		for(int i = 0;i < vp;i++)vs[i][3] = i;

		int[][] vsu = Arrays.copyOf(vs, vs.length);
		Arrays.sort(vsu, new Comparator<int[]>() {
			public int compare(int[] a, int[] b) {
				return a[2] - b[2];
			}
		});

		long ans = 0;
		for(int i = 0;i < hp;i++){
			int[] ft = new int[n+3];
			int p = vp-1;
			for(int j = hp-1;j >= i+1;j--){
				while(p >= 0 && vsu[p][2] >= hs[j][0]){
					if(vsu[p][1] <= hs[i][0]){
						addFenwick(ft, vsu[p][3], 1);
					}
					p--;
				}

				int L = lowerBound(vs, 0, Math.max(hs[i][1], hs[j][1]))-1;
				int R = lowerBound(vs, 0, Math.min(hs[i][2], hs[j][2])+1)-1;
				if(L < R){
					int u = sumFenwick(ft, R) - sumFenwick(ft, L);
					ans += (long)u * (u-1) / 2;
				}
			}
		}
		out.println(ans);
	}

	public static int lowerBound(int[][] a, int ind, int v)
	{
		int low = -1, high = a.length;
		while(high-low > 1){
			int h = high+low>>>1;
			if(a[h][ind] >= v){
				high = h;
			}else{
				low = h;
			}
		}
		return high;
	}

	public static int sumFenwick(int[] ft, int i)
	{
		int sum = 0;
		for(i++;i > 0;i -= i&-i)sum += ft[i];
		return sum;
	}

	public static void addFenwick(int[] ft, int i, int v)
	{
		if(v == 0 || i < 0)return;
		int n = ft.length;
		for(i++;i < n;i += i&-i)ft[i] += v;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new E2().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


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

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		ArrayList<Line> h = new ArrayList<>();
		ArrayList<Line> v = new ArrayList<>();
		int n = fs.nextInt();
		for(int i = 0; i < n; i++) {
			int x = fs.nextInt(), y = fs.nextInt();
			int x1 = fs.nextInt(), y1 = fs.nextInt();
			boolean hori = y == y1;
			Line add = new Line(hori);
			if(hori) {
				add.y = y1;
				add.x = x; add.x1 = x1;
			}
			else {
				add.x = x;
				add.y = y; add.y1 = y1;
			}
			add.set();
			if(hori) h.add(add);
			else v.add(add);
		}

		myBitSet[] a = new myBitSet[h.size()];
		for(int i = 0; i < a.length; i++) {
			a[i] = new myBitSet(v.size());
		}
		for(int i = 0; i < h.size(); i++) {
			Line me = h.get(i);
			for(int j = 0; j < v.size(); j++) {
				Line you = v.get(j);
				boolean hits = you.y <= me.y && me.y <= you.y1;
				hits &= me.x <= you.x && you.x <= me.x1;
				if(hits) {
					a[i].set(j);
				}
			}
		}

		long res = 0;
		for(int i = 0; i < a.length; i++) {
			for(int j = i+1; j < a.length; j++) {
				int sz = a[i].andC(a[j]);
				res += sz * (sz-1)/2;
			}
		}
		out.println(res);

		out.close();
	}

	class myBitSet {
		long[] bits;
		int n, m;
		myBitSet(int nn) {
			n = nn;
			m = nn/60 + (nn % 60 > 0 ? 1 : 0);
			bits = new long[m];
		}
		void set(int i) {
			int idx = i/60;
			int bit = i-idx*60;
			bits[idx] |= 1L << bit;
		}
		int andC(myBitSet b) {
			int res = 0;
			for(int i = 0; i < bits.length; i++) {
				long temp = bits[i] & b.bits[i];
				res += Long.bitCount(temp);
			}
			return res;
		}
	}

	class Line {
		boolean hori;
		int x, x1, y, y1;
		Line(boolean h) {
			hori = h;
		}
		void set() {
			if(hori) {
				int mn = Math.min(x, x1);
				int mx = Math.max(x, x1);
				x = mn; x1 = mx;
			}
			else {
				int mn = Math.min(y, y1);
				int mx = Math.max(y, y1);
				y = mn; y1 = mx;
			}
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}


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

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		ArrayList<Line> h = new ArrayList<>();
		ArrayList<Line> v = new ArrayList<>();
		int n = fs.nextInt();
		for(int i = 0; i < n; i++) {
			int x = fs.nextInt(), y = fs.nextInt();
			int x1 = fs.nextInt(), y1 = fs.nextInt();
			boolean hori = y == y1;
			Line add = new Line(hori);
			if(hori) {
				add.y = y1;
				add.x = x; add.x1 = x1;
			}
			else {
				add.x = x;
				add.y = y; add.y1 = y1;
			}
			add.set();
			if(hori) h.add(add);
			else v.add(add);
		}

		BitSet[] a = new BitSet[h.size()];
		for(int i = 0; i < a.length; i++) {
			a[i] = new BitSet(v.size());
		}
		for(int i = 0; i < h.size(); i++) {
			Line me = h.get(i);
			for(int j = 0; j < v.size(); j++) {
				Line you = v.get(j);
				boolean hits = you.y <= me.y && me.y <= you.y1;
				hits &= me.x <= you.x && you.x <= me.x1;
				if(hits) {
					a[i].set(j);
				}
			}
		}

		long res = 0;
		for(int i = 0; i < a.length; i++) {
			for(int j = i+1; j < a.length; j++) {
				BitSet clone = (BitSet)a[i].clone();
				clone.and(a[j]);
				int sz = clone.cardinality();
				res += sz * (sz-1)/2;
			}
		}
		out.println(res);

		out.close();
	}

	class Line {
		boolean hori;
		int x, x1, y, y1;
		Line(boolean h) {
			hori = h;
		}
		void set() {
			if(hori) {
				int mn = Math.min(x, x1);
				int mx = Math.max(x, x1);
				x = mn; x1 = mx;
			}
			else {
				int mn = Math.min(y, y1);
				int mx = Math.max(y, y1);
				y = mn; y1 = mx;
			}
		}
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}


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

public class RectCount {
	static BufferedReader br;
	static StringTokenizer tokenizer;

	public static void main(String[] args) throws Exception {
		br = new BufferedReader(new InputStreamReader(System.in));
		int n = nextInt();
		BIT b;
		boolean[] intersects;
		ArrayList<CLine> vert = new ArrayList<CLine>(5000);
		ArrayList<CLine> hori = new ArrayList<CLine>(5000);
		for (int i = 0; i < n; i++) {
			int x, y, x1, y1;
			x = nextInt();
			y = nextInt();
			x1 = nextInt();
			y1 = nextInt();
			if (y > y1) {
				int t = y1;
				y1 = y;
				y = t;
			}
			if (x > x1) {
				int t = x1;
				x1 = x;
				x = t;
			}
			if (x == x1)
				vert.add(new CLine(x, x1, y, y1));
			else
				hori.add(new CLine(x, x1, y, y1));
		}
		hori.sort(null);
		vert.sort(null);
		long sum = 0;
		for (int i = 0; i < hori.size(); i++) {
			b = new BIT(10001);
			intersects = new boolean[vert.size()];
			for (int j = 0; j < vert.size(); j++)
				if (checkIntersect(vert.get(j), hori.get(i))) {
					b.add(vert.get(j).x + 5000, 1);
					intersects[j] = true;
				}
			int k = 0;
			for (int j = i + 1; j < hori.size(); j++) {
				while (k < vert.size() && vert.get(k).y1 < hori.get(j).y1) {
					if(intersects[k])
						b.add(vert.get(k).x + 5000, -1);
					k++;
				}
				if (hori.get(j).x < hori.get(i).x1 && hori.get(i).x < hori.get(j).x1) {
					int t = b.get(Math.max(hori.get(j).x, hori.get(i).x) + 5000,
							Math.min(hori.get(j).x1, hori.get(i).x1) + 5001);
//					System.out.println("t " + t);
					t--;
					sum += (long) t * (t + 1) / 2;
				}
			}
//			System.out.println(sum);
		}
		System.out.println(sum);
	}

	public static boolean checkIntersect(CLine v, CLine h) {
		if (h.x <= v.x && v.x <= h.x1 && v.y <= h.y && h.y <= v.y1)
			return true;
		return false;
	}

	public static String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null)
				throw new IOException();
			tokenizer = new StringTokenizer(line);
		}
		return tokenizer.nextToken();
	}

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

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

	public static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
}

class CLine implements Comparable<CLine> {
	int x, x1, y, y1;

	public CLine(int x, int x1, int y, int y1) {
		super();
		this.x = x;
		this.x1 = x1;
		this.y = y;
		this.y1 = y1;
	}

	@Override
	public int compareTo(CLine o) {
		if (y1 != o.y1)
			return y1 - o.y1;
		return x - o.x;
	}
}

class BIT {
	int[] BIT;
	int n;

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

	public BIT(int[] BIT) {
		this.BIT = BIT;
		n = BIT.length;
	}

	// [idx]
	void add(int idx, int val) {
		idx++;
		for (; idx < n; idx += (idx & (-idx)))
			BIT[idx] += val;
	}

	// [0,l]
	int get(int idx) {
		idx++;
		int ret = 0;
		for (; idx > 0; idx -= (idx & (-idx)))
			ret += BIT[idx];
		return ret;
	}

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