#import <stdio.h>
double FLOOR(double x) {
    long n = (long)x;
    return n + (((x != n) && (x < 0)) ? -1 : 0);
}
double ROUND(double x) {
    double n = FLOOR(x);
    double d = x - n;
    return ((x>=0)&&(d<0.5))||((x<0)&&(d<=0.5)) ? n : n+1;
}
double SQRT(double x) {
    double xHalf = 0.5 * x;
    long tmp = 0x5FE6EB50C7B537AAl - ( *(long*)&x >> 1); //initial guess
    double xRes = * (double*)&tmp;
    
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    return xRes * x;
}
int main(){
    int n,d;
    scanf("%d %d",&n,&d);
    int x[10][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            int y;
            scanf("%d",&y);
            x[i][j] = y;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int L = 0;
            for (int k=0;k<d;k++){
                L += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int p = (int)(ROUND(SQRT((double)L)));
            if(p*p==L) ans++;
        }
    }
    printf("%d",ans);
}
