---------------
const int maxn=4100; const int maxm=10000; int n,m; int a[4][maxn]; int b[maxn*maxn]; int main(){ while (~scanf("%d",&n)){ for (int i=0;i<n;i++){ for (int k=0;k<4;k++){ scanf("%d",&a[k][i]); } } for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ b[i*n+j]=a[0][i]+a[1][j]; } } m=n*n; sort(b,b+m); int ans=0; for (int i=0;i<n;i++){ for (int j=0;j<n;j++){ int t=a[2][i]+a[3][j]; int l=lower_bound(b,b+m,-t)-b; int r=upper_bound(b,b+m,-t)-b; ans+=r-l; } } printf("%d ",ans); } return 0; }
---------------