#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxN 100012
#define maxV 70
struct Triple{
long a,b,c;
};
long n,i,Ans;
Triple Tr[maxN];
long how[maxV][maxV][maxV];
long getCnt(long val){
long ans=0;
for(long i=2;i*i<=val;i++){
long cnt=0;
while(val%i==0) {cnt++; val/=i;}
if(cnt>1) return -1;
if(cnt) ans++;
}
if(val!=1) ans++;
return ans;
}
int main()
{
freopen("puteri.in","r",stdin);
freopen("puteri.out","w",stdout);
scanf("%ld",&n);
for(i=1;i<=n;i++) scanf("%ld%ld%ld",&Tr[i].a,&Tr[i].b,&Tr[i].c);
for(long pas = 2;pas<maxV*2;pas++){
long sg = getCnt(pas);
if(sg==-1) continue;
if(sg%2==0) sg=-1; else sg=1;
memset(how,0,sizeof(how));
for(i=1;i<=n;i++){
Triple tmp = Tr[i];
tmp.a%=pas; tmp.b%=pas ; tmp.c%=pas;
tmp.a = pas - tmp.a;
tmp.b = pas - tmp.b;
tmp.c = pas - tmp.c;
tmp.a%=pas; tmp.b%=pas ; tmp.c%=pas;
if(tmp.a < maxV && tmp.b < maxV && tmp.c < maxV) Ans += sg*how[tmp.a][tmp.b][tmp.c];
tmp = Tr[i]; tmp.a%=pas; tmp.b%=pas ; tmp.c%=pas;
how[tmp.a][tmp.b][tmp.c]++;
}
}
printf("%ld",Ans);
return 0;
}