20分
#include<bits/stdc++.h>
using namespace std;
int a[1005],b[1005],c[1005],d[1005];
int n,ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>a[i]>>b[i]>>c[i];
d[i]=a[i]+b[i]+c[i];
}
for(int i=1;i<=n;++i){
for(int j=i+1;j<=n;++j){
if((abs(a[i]-a[j])<=5) && (abs(b[i]-b[j])<=5) && (abs(c[i]-c[j])<=5) && (abs(d[i]-d[j]<=10)))
ans++;
}
}cout<<ans;
return 0;
}