#include <stdio.h>
#include <stdlib.h>
#define MAXA 1010
int main(void)
{
int n, ans = 0;
int chi[MAXA], mat[MAXA], eng[MAXA], tot[MAXA];
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
scanf("%d %d %d", &chi[i], &mat[i], &eng[i]);
tot[i] = chi[i] + mat[i] + eng[i];
}
for(int i = 1; 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))
ans++;
printf("%d\n", ans);
return 0;
}