import java.util.*;
class Main{
	public static void main(String[] args){
    
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt() , d = s.nextInt();
      	long[][] arr = new long[n][d];
      
      	for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } 
      
      int count = 0;
      long ans = 0;
    
      for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      }
      
      System.out.println(count);
      
    }
  
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
    
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt() , d = s.nextInt();
      	long[][] arr = new long[n][d];
      
      	for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } 
      
      int count = 0;
      long ans = 0;
    
      for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      }
      
      System.out.println(count);
      
    }
  
} Main public static void main(String[] args){
    
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt() , d = s.nextInt();
      	long[][] arr = new long[n][d];
      
      	for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } 
      
      int count = 0;
      long ans = 0;
    
      for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      }
      
      System.out.println(count);
      
    } main {
    
    	Scanner s = new Scanner(System.in);
        int n = s.nextInt() , d = s.nextInt();
      	long[][] arr = new long[n][d];
      
      	for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } 
      
      int count = 0;
      long ans = 0;
    
      for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      }
      
      System.out.println(count);
      
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt() n s.nextInt() s.nextInt s d = s.nextInt(); d s.nextInt() s.nextInt s long[][] arr = new long[n][d]; arr new long[n][d] n d for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } {
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } int j = 0; int j = 0; j 0 j < d j d ++j ++j j {
            	arr[i][j] = s.nextLong();
            } {
            	arr[i][j] = s.nextLong();
            } arr[i][j] = s.nextLong() arr[i][j] arr[i] arr i j s.nextLong() s.nextLong s int count = 0; count 0 long ans = 0; ans 0 for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      } {
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      } for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        } {
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        } long val = 0; val 0 for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            } int k = 0; int k = 0; k 0 k < d k d ++k ++k k {
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            } {
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            } val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ) val Math.pow( (arr[j][k] - arr[i][k]) , 2 ) Math.pow Math (arr[j][k] - arr[i][k]) arr[j][k] arr[j] arr j k arr[i][k] arr[i] arr i k 2 long a = (long)Math.sqrt(val); a (long)Math.sqrt(val) Math.sqrt Math val if(a*a == val) count++; a*a == val a*a a a val count++ count 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 s = new Scanner(System.in);
        int n = s.nextInt() , d = s.nextInt();
      	long[][] arr = new long[n][d];
      
      	for(int i = 0;i < n;i++){
        	for(int j = 0;j < d;++j){
            	arr[i][j] = s.nextLong();
            } 
        } 
      
      int count = 0;
      long ans = 0;
    
      for(int i = 0;i < n;i++){
      
      	for(int j = i + 1;j < n;j++){
        
          long val = 0;
        	for(int k = 0;k < d;++k){
            	val += Math.pow( (arr[j][k] - arr[i][k]) , 2 ); 
            }
          
          long a = (long)Math.sqrt(val);
          if(a*a == val) count++;
        
        }
      
      }
      
      System.out.println(count);
      
    }
  
}