
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
} Main public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	} main {
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int N = input.nextInt(); N input.nextInt() input.nextInt input int D = input.nextInt(); D input.nextInt() input.nextInt input int X[][] = new int[N][D]; X new int[N][D] N D for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.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] = input.nextInt();
			}
		} {
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		} for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = input.nextInt();
			} {
				X[i][j] = input.nextInt();
			} X[i][j] = input.nextInt() X[i][j] X[i] X i j input.nextInt() input.nextInt input int totalInt = 0; totalInt 0 for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		} int k = 0; int k = 0; k 0 k < N k N k++ k++ k {
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		} {
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		} for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			} int l = k+1; int l = k+1; l k+1 k 1 l < N l N l++ l++ l {
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			} {
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			} int sum = 0; sum 0 for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				} {
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				} sum += Math.pow((X[k][j]-X[l][j]), 2) sum Math.pow((X[k][j]-X[l][j]), 2) Math.pow Math (X[k][j]-X[l][j]) X[k][j] X[k] X k j X[l][j] X[l] X l j 2 double dist = Math.pow(sum, .5); dist Math.pow(sum, .5) Math.pow Math sum .5 if(dist == (int)dist){
					totalInt++;
				} dist == (int)dist dist (int)dist {
					totalInt++;
				} totalInt++ totalInt System.out.println(totalInt) System.out.println System.out System System.out totalInt String[] args args public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
} public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int D = input.nextInt();
      
		int X[][] = new int[N][D];
	
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = input.nextInt();
			}
		}
		int totalInt = 0;
		for(int k = 0; k < N; k++){
			
			for(int l = k+1; l < N; l++){
				int sum = 0; 
				for(int j = 0; j < D; j++){
					sum += Math.pow((X[k][j]-X[l][j]), 2);
				}
				double dist = Math.pow(sum, .5);
				if(dist == (int)dist){
					totalInt++;
				}
			}
				
		}
		System.out.println(totalInt);
		
		
	}	
}
