import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),d = sc.nextInt();
        int[][] x = new int[n][d];
        int count = 0;
        for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        }
        for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        }
        System.out.println(count);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),d = sc.nextInt();
        int[][] x = new int[n][d];
        int count = 0;
        for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        }
        for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        }
        System.out.println(count);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),d = sc.nextInt();
        int[][] x = new int[n][d];
        int count = 0;
        for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        }
        for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),d = sc.nextInt();
        int[][] x = new int[n][d];
        int count = 0;
        for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        }
        for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int[][] x = new int[n][d]; x new int[n][d] n d int count = 0; count 0 for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        } {
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        } for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j<d j d j++ j++ j {
                x[i][j] = sc.nextInt();
            } {
                x[i][j] = sc.nextInt();
            } x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        } {
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        } int j = i+1; j i+1 i 1 while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            } j<n j n {
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            } int tmp = 0; tmp 0 for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                } int k = 0; int k = 0; k 0 k<d k d k++ k++ k {
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                } {
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                } tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]) tmp (x[i][k]-x[j][k])*(x[i][k]-x[j][k]) (x[i][k]-x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k]-x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k int l =1; l 1 while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                } l*l<=tmp l*l l l tmp {
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                } if(l*l==tmp){
                        count ++;
                    } l*l==tmp l*l l l tmp {
                        count ++;
                    } count ++ count l ++ l j++ j System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),d = sc.nextInt();
        int[][] x = new int[n][d];
        int count = 0;
        for(int i = 0;i<n;i++){
            for(int j = 0;j<d;j++){
                x[i][j] = sc.nextInt();
            }
        }
        for(int i = 0;i<n;i++){
            int j = i+1;
            while(j<n){
                int tmp = 0;
                for(int k = 0;k<d;k++){
                    tmp += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
                }
                int l =1;
                while(l*l<=tmp){
                    if(l*l==tmp){
                        count ++;
                    }
                    l ++;
                }
                j++;
            }
        }
        System.out.println(count);
    }
}