#include<bits/stdc++.h>
using namespace std;
int tu[10001],su[10001],yu[10001];
int main()
{
int t,s,y,n,u,q,c1,c2,c3,qi=0;
q=0-10;
cin>>n;
for(int i=1;i<=n;i+=1)
{
cin>>t>>s>>y;
tu[i]=t;
su[i]=s;
yu[i]=y;
}
for(u=1;u<=n;u+=1)
{
for(int p=u;p<=n;p+=1)
{
int o=0,e,c;
e=p+1;
cout<<e;
o=o+tu[u]-tu[e];
o=o+su[u]-su[e];
o=o+yu[u]-yu[e];
if(o<=10||o>=q)
{
c1=tu[u]-tu[e];
c2=su[u]-su[e];
c3=yu[u]-yu[e];
if(c1<=5&&c2<=5&&c3<=5)
{
qi+=1;
}
}
}
}
cout<<qi;
return 0;
}