#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[4000], b[4000], c[4000], d[4000];
int list[16000000];
int main() {
//freopen("input.txt", "rt", stdin);
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d%d%d%d", a + i, b + i, c + i, d + i);
int k=0;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j,++k)
list[k]=a[i]+b[j];
sort(list,list+k);
int res = 0;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
res+=upper_bound(list,list+k,(c[i]+d[j])*-1)-lower_bound(list,list+k,(c[i]+d[j])*-1);
printf("%d",res);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFbNDAwMF0sIGJbNDAwMF0sIGNbNDAwMF0sIGRbNDAwMF07CmludCBsaXN0WzE2MDAwMDAwXTsKaW50IG1haW4oKSB7CgkvL2ZyZW9wZW4oImlucHV0LnR4dCIsICJydCIsIHN0ZGluKTsKCWludCBuOwoJc2NhbmYoIiVkIiwgJm4pOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpCgkJc2NhbmYoIiVkJWQlZCVkIiwgYSArIGksIGIgKyBpLCBjICsgaSwgZCArIGkpOwoJaW50IGs9MDsKCWZvcihpbnQgaT0wO2k8bjsrK2kpCglmb3IoaW50IGo9MDtqPG47KytqLCsraykKCQlsaXN0W2tdPWFbaV0rYltqXTsKCXNvcnQobGlzdCxsaXN0K2spOwoJaW50IHJlcyA9IDA7Cglmb3IoaW50IGk9MDtpPG47KytpKQoJCWZvcihpbnQgaj0wO2o8bjsrK2opCgkJCXJlcys9dXBwZXJfYm91bmQobGlzdCxsaXN0K2ssKGNbaV0rZFtqXSkqLTEpLWxvd2VyX2JvdW5kKGxpc3QsbGlzdCtrLChjW2ldK2Rbal0pKi0xKTsKCXByaW50ZigiJWQiLHJlcyk7Cn0K