#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 4051;
int A[N], B[N], C[N], D[N], CD[N * N];
int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        for (int i = 0; i < n; i++)
            scanf("%d%d%d%d", A + i, B + i, C + i, D + i);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                CD[i * n + j] = C[i] + D[j];
        sort(CD, CD + n * n);
        long long sum = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                sum += upper_bound(CD, CD + n * n, -(A[i] + B[j])) - lower_bound(CD, CD + n * n, -(A[i] + B[j]));
        printf("%lld\n", sum);
    }
    return 0;
}