import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int ans=0; ans 0 double wk=0; wk 0 int wk1=0; wk1 0 int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int D=sc.nextInt(); D sc.nextInt() sc.nextInt sc int X [][] = new int[N][D]; X new int[N][D] N D for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		} int i=1; int i=1; i 1 i<=N i N i++ i++ i {		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		} {		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		} for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			} int j=1; int j=1; j 1 j<=D j D j++ j++ j {	
				X [i-1][j-1]=sc.nextInt();	
			} {	
				X [i-1][j-1]=sc.nextInt();	
			} X [i-1][j-1]=sc.nextInt() X [i-1][j-1] X [i-1] X i-1 i 1 j-1 j 1 sc.nextInt() sc.nextInt sc for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		} int i=1; int i=1; i 1 i<N i N i++ i++ i {		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		} {		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		} for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			} int j=i+1; int j=i+1; j i+1 i 1 j<=N j N j++ j++ j {	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			} {	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			} for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				} int k=1; int k=1; k 1 k<=D k D k++ k++ k {	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				} {	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				} wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk wk (X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk (X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1]) (X [i-1][k-1]-X [j-1][k-1]) X [i-1][k-1] X [i-1] X i-1 i 1 k-1 k 1 X [j-1][k-1] X [j-1] X j-1 j 1 k-1 k 1 (X [i-1][k-1]-X [j-1][k-1]) X [i-1][k-1] X [i-1] X i-1 i 1 k-1 k 1 X [j-1][k-1] X [j-1] X j-1 j 1 k-1 k 1 wk wk=Math.sqrt(wk) wk Math.sqrt(wk) Math.sqrt Math wk if(wk==Math.ceil(wk)){ans=ans+1;} wk==Math.ceil(wk) wk Math.ceil(wk) Math.ceil Math wk {ans=ans+1;} ans=ans+1 ans ans+1 ans 1 wk=0 wk 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int ans=0;			double wk=0;	int wk1=0;
		int N=sc.nextInt();	
		int D=sc.nextInt();	

		int X [][] = new int[N][D];		
		for(int i=1; i<=N;i++){		
			for(int j=1;j<=D;j++){	
				X [i-1][j-1]=sc.nextInt();	
			}			
		}
		for(int i=1; i<N;i++){		
			for(int j=i+1;j<=N;j++){	
				for(int k=1;k<=D;k++){	
				wk=(X [i-1][k-1]-X [j-1][k-1])*(X [i-1][k-1]-X [j-1][k-1])+wk;
				}	
				wk=Math.sqrt(wk);
				if(wk==Math.ceil(wk)){ans=ans+1;}
				wk=0;
			}			
		}	
		
	
	System.out.println(ans);
	}
}