import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} 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, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N, D, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N D D ans; ans 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 sc.close() sc.close sc ans = 0 ans 0 for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			} 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.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			} {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			} int sum = 0; sum 0 for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				} {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				} sum += Math.pow(X[i][k] - X[j][k], 2) sum 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 double rs = Math.sqrt(sum); rs Math.sqrt(sum) Math.sqrt Math sum if (rs == (int) rs) {
					ans++;
				} rs == (int) rs rs (int) rs {
					ans++;
				} ans++ ans 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 N, D, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, D, ans;
		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();
			}
		}
		sc.close();
		ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(X[i][k] - X[j][k], 2);
				}
				double rs = Math.sqrt(sum);
				if (rs == (int) rs) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

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