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