//poj 2785 //在本机开320W的int数组,会提示错误。但提交OK。 import java.util.*; import java.io.*; public class Main { public static int asc_lower_bound(int[] arr, int left, int right, int number) { int mid; while (left <= right) { mid = (left + right) >> 1; if (arr[mid] >= number) right = mid - 1; else left = mid + 1; } return left; } public static int asc_higher_bound(int[] arr, int left, int right, int number) { int mid; while (left <= right) { mid = (left + right) >> 1; if (arr[mid] > number) right = mid - 1; else left = mid + 1; } return right; } public static void main(String[] args) { int[] x = new int[4000 * 4000]; int[] y = new int[4000 * 4000]; int[][] a = new int[4000][4]; Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int N = n * n; int i, j, k, t; for (i = 0; i < n; ++i) for (j = 0; j < 4; ++j) a[i][j] = cin.nextInt(); for (i = k = 0; i < n; ++i) for (j = 0; j < n; ++j, ++k) x[k] = a[i][0] + a[j][1]; for (i = k = 0; i < n; ++i) for (j = 0; j < n; ++j, ++k) y[k] = a[i][2] + a[j][3]; Arrays.sort(y, 0, N); for (i = k = 0; i < N; ++i) k += asc_higher_bound(y, 0, N - 1, -x[i]) - asc_lower_bound(y, 0, N - 1, -x[i]) + 1; System.out.println(k); } }