import java.util.Scanner;

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

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int N, D;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N D; D N = sc.nextInt() N sc.nextInt() sc.nextInt sc 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 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 int cnt = 0; cnt 0 for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			} {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			} int sum = 0; sum 0 for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				} {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				} sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]) sum Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]) Math.abs(X[i][k] - X[j][k]) Math.abs Math X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k Math.abs(X[i][k] - X[j][k]) Math.abs Math X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				} Math.sqrt(sum) % 1 == 0 Math.sqrt(sum) % 1 Math.sqrt(sum) Math.sqrt Math sum 1 0 {
					cnt++;
				} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D;
		N = sc.nextInt();
		D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}
} Main
import java.util.Scanner;

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

		int cnt = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.abs(X[i][k] - X[j][k]) * Math.abs(X[i][k] - X[j][k]);
				}
				if (Math.sqrt(sum) % 1 == 0) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}
}
