import java.util.Scanner;

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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	}
} import java.util.Scanner; Scanner 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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	}
} 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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	} main {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int D = sc.nextInt();
		
		int[][] X = new int[N][D];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	} 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 for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		} {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		} for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			} int p=0; int p=0; p 0 p<D p D p++ p++ p {
				X[i][p] = sc.nextInt();
			} {
				X[i][p] = sc.nextInt();
			} X[i][p] = sc.nextInt() X[i][p] X[i] X i p sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		} {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		} for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			} int p=i+1; int p=i+1; p i+1 i 1 p<N p N p++ p++ p {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			} {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			} double total = 0; total 0 for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				} int d =0; int d =0; d 0 d<D d D d++ d++ d {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				} {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				} double a =Math.pow(X[i][d] - X[p][d],2); a Math.pow(X[i][d] - X[p][d],2) Math.pow Math X[i][d] - X[p][d] X[i][d] X[i] X i d X[p][d] X[p] X p d 2 total += a total a total = Math.sqrt(total) total Math.sqrt(total) Math.sqrt Math total if(total % 1 == 0) {
					count ++;
				} total % 1 == 0 total % 1 total 1 0 {
					count ++;
				} count ++ count System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc 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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	}
} 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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	}
} Main
import java.util.Scanner;

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];
		for(int i=0;i<N;i++) {
			for(int p=0;p<D;p++) {
				X[i][p] = sc.nextInt();
			}
		}
		
		int count = 0;
		for(int i=0;i<N;i++) {
			for(int p=i+1;p<N;p++) {
				double total = 0;
				for(int d =0;d<D;d++) {
					double a =Math.pow(X[i][d] - X[p][d],2); 
					total += a;
				}
				total = Math.sqrt(total);
				if(total % 1 == 0) {
					count ++;
				}
			}
		}
		System.out.println(count);	
		sc.close();	
	}
}