import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc int [][] in = new int [n][d]; in new int [n][d] n d for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[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++){
                             in[i][j] = sc.nextInt();
                            }
                            } {
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            } for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            } int j=0; int j=0; j 0 j<d j d j++ j++ j {
                             in[i][j] = sc.nextInt();
                            } {
                             in[i][j] = sc.nextInt();
                            } in[i][j] = sc.nextInt() in[i][j] in[i] in i j sc.nextInt() sc.nextInt sc int b = 0; b 0 int c = 0; c 0 for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        } {
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        } for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                } {c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                } c=0 c 0 for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);} int k=0; int k=0; k 0 k<d k d k++ k++ k {c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);} {c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);} c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]) c (in[i][k]-in[j][k])*(in[i][k]-in[j][k]) (in[i][k]-in[j][k]) in[i][k] in[i] in i k in[j][k] in[j] in j k (in[i][k]-in[j][k]) in[i][k] in[i] in i k in[j][k] in[j] in j k for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                } int l=0; int l=0; l 0 l<=Math.sqrt(c) l Math.sqrt(c) Math.sqrt Math c l++ l++ l {if(l*l==c){b++;}
                                                                } {if(l*l==c){b++;}
                                                                } if(l*l==c){b++;} l*l==c l*l l l c {b++;} b++ b System.out.println(b) System.out.println System.out System System.out b String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int d = sc.nextInt();
		int [][] in = new int [n][d];
        for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
                             in[i][j] = sc.nextInt();
                            }
                            }
        int b = 0;
        int c = 0;
        for(int i=0;i<n-1;i++){
          for(int j=i+1;j<n;j++){c=0;
          for(int k=0;k<d;k++){c+=(in[i][k]-in[j][k])*(in[i][k]-in[j][k]);}
                                for(int l=0;l<=Math.sqrt(c);l++){if(l*l==c){b++;}
                                                                }                                       
                                }                            
        }      
		System.out.println(b);
	}
}
