import java.util.Scanner;

class Main {
    
    public static void main (String[] args){
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int D = sc.nextInt();
        
        int [] list = new int [N*D];
        
        for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        }
        
        int count = 0;
        for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        }
        
        System.out.println(count);
        
        
    }
} import java.util.Scanner; Scanner java.util class Main {
    
    public static void main (String[] args){
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int D = sc.nextInt();
        
        int [] list = new int [N*D];
        
        for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        }
        
        int count = 0;
        for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        }
        
        System.out.println(count);
        
        
    }
} Main public static void main (String[] args){
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int D = sc.nextInt();
        
        int [] list = new int [N*D];
        
        for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        }
        
        int count = 0;
        for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        }
        
        System.out.println(count);
        
        
    } main {
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int D = sc.nextInt();
        
        int [] list = new int [N*D];
        
        for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        }
        
        int count = 0;
        for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        }
        
        System.out.println(count);
        
        
    } Main main = new Main (); main new Main () 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 [] list = new int [N*D]; list new int [N*D] N*D N D for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        } int index=0; int index=0; index 0 index<N*D index N*D N D index++ index++ index {
            list[index]=sc.nextInt();
        } {
            list[index]=sc.nextInt();
        } list[index]=sc.nextInt() list[index] list index sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        } int index=0; int index=0; index 0 index<N index N index++ index++ index {
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        } {
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        } for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            } int index2=index+1; int index2=index+1; index2 index+1 index 1 index2<N index2 N index2++ index2++ index2 {
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            } {
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            } double  sum = 0; sum 0 for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                } int index3=0; int index3=0; index3 0 index3<D index3 D index3++ index3++ index3 {
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                } {
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                } sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3])) sum Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3])) Math.abs Math (list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]) (list[index*D+index3]-list[index2*D+index3]) list[index*D+index3] list index*D+index3 index*D index D index3 list[index2*D+index3] list index2*D+index3 index2*D index2 D index3 (list[index*D+index3]-list[index2*D+index3]) list[index*D+index3] list index*D+index3 index*D index D index3 list[index2*D+index3] list index2*D+index3 index2*D index2 D index3 sum=Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum if (sum%1==0){
                    count++;
                } sum%1==0 sum%1 sum 1 0 {
                    count++;
                } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

class Main {
    
    public static void main (String[] args){
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int D = sc.nextInt();
        
        int [] list = new int [N*D];
        
        for (int index=0; index<N*D; index++){
            list[index]=sc.nextInt();
        }
        
        int count = 0;
        for (int index=0; index<N; index++){
            
            for (int index2=index+1; index2<N; index2++){
                
                double  sum = 0;
                
                for (int index3=0; index3<D; index3++){
                    
                    sum+=Math.abs((list[index*D+index3]-list[index2*D+index3])*(list[index*D+index3]-list[index2*D+index3]));
                }
                
                sum=Math.sqrt(sum);
                
                if (sum%1==0){
                    count++;
                }
            }
        }
        
        System.out.println(count);
        
        
    }
}