#include <iostream>
#include <stdio.h>
using namespace std;
int nprm[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127 };
int pos[65][65][65];
int pus[129];
int ab[100001][3];
int n;
int i,j,k;
int npos, npc;
int pos1( int i )
{
int x = 0;
int a,b,c,a1,b1,c1;
int j;
bzero( pos, sizeof( pos ) );
for ( j = 1; j <= n; j++ )
pos[ ab[j][0]%i ][ ab[j][1]%i ][ ab[j][2]%i ]++;
for ( a = 0; a < min(i,64); a++ )
for ( b = 0; b < min(i,64); b++ )
for ( c = 0; c < min(i,64); c++ )
if ( pos[a][b][c] )
{
a1 = (i - a)%i;
b1 = (i - b)%i;
c1 = (i - c)%i;
if ( a1 <= 64 && b1 <= 64 && c1<=64 )
if ( pos[ a1 ][ b1 ][ c1 ] )
{
if ( a1 == a && b1 == b && c1 == c )
x += pos[a][b][c]*(pos[a][b][c] - 1 );
else
x += pos[a][b][c]*pos[a1][b1][c1];
}
}
return x/2;
}
void back( int k, int lung, int pc, int last )
{
int i;
if ( k > 1 )
{
if ( (k-1) % 2 == 0 )
npos -= pos1(pc);
else
npos += pos1(pc);
}
if ( k <= lung )
{
for ( i = last+1; i <= 30; i++ )
{
if ( pc*nprm[i] <= 128 )
back( k+1, lung, pc*nprm[i], i);
}
}
}
int main()
{
int a,b,c;
freopen("puteri.in","r",stdin);
freopen("puteri.out","w",stdout);
scanf("%d\n", &n);
for ( i = 1; i <= n; i++ )
scanf("%d %d %d\n", &ab[i][0], &ab[i][1], &ab[i][2] );
back(1,4,1,-1);
printf("%d\n", npos);
return 0;
}