#include <iostream>;
using namespace std;
int main()
{
int chi[1002], mat[1002], eng[1002], tot[1002];
int n,answer=0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> chi[i] >> mat[i] >> eng[i];
tot[i] = chi[i] + mat[i] + eng[i];
}
for (int i = 0; i < n; i++)
for(int j=i+1;j<n;j++)
{
if ((abs(chi[i] - chi[j]) <= 5)&&(abs(mat[i] - mat[j])) <= 5 && (abs(eng[i] - eng[j]) )<= 5 && (abs(tot[i] - tot[j])) <= 10);
answer++;
}
cout << answer;
return 0;
}