import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	}
} import java.util.*; util.* java public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

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

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	}
} Main
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int D  = keyboard.nextInt();
		
		int[][]X = new int[N][D];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				X[i][j] = keyboard.nextInt();	
			}
		}
		
		int count = 0;
		double a = 0;

		for(int i = 0; i < N; i++) {
			for(int j = i+1; j < N; j++) {
				a = 0;
				for(int k = 0; k < D; k++) {
					a += Math.pow(X[i][k]-X[j][k],2);
				}
				if(Math.sqrt(a)%1.0 == 0.0) {
					count++;
				}
			}
		}
		
		System.out.println(count);
		keyboard.close();	
	}
}
