import java.util.Scanner;

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

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}

	static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}

	static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	}
} Main public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	} main {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	} try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		} {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		} Scanner s = new Scanner(System.in) Scanner s = new Scanner(System.in) new Scanner(System.in) final int N = s.nextInt(); N s.nextInt() s.nextInt s final int D = s.nextInt(); D s.nextInt() s.nextInt s final 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] = s.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] = s.nextInt();
				}
			} {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			} for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
					X[i][j] = s.nextInt();
				} {
					X[i][j] = s.nextInt();
				} X[i][j] = s.nextInt() X[i][j] X[i] X i j s.nextInt() s.nextInt s int ret = 0; ret 0 for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			} {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			} for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
					if (calc(X[i], X[j])) {
						ret++;
					}
				} {
					if (calc(X[i], X[j])) {
						ret++;
					}
				} if (calc(X[i], X[j])) {
						ret++;
					} calc(X[i], X[j]) calc X[i] X i X[j] X j {
						ret++;
					} ret++ ret System.out.println(ret) System.out.println System.out System System.out ret String[] args args static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	} calc {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	} int sum = 0; sum 0 for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		} int i = 0; int i = 0; i 0 i < x1.length i x1.length x1 x1.length i++ i++ i {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		} {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		} sum += (x2[i] - x1[i]) * (x2[i] - x1[i]) sum (x2[i] - x1[i]) * (x2[i] - x1[i]) (x2[i] - x1[i]) x2[i] x2 i x1[i] x1 i (x2[i] - x1[i]) x2[i] x2 i x1[i] x1 i return Math.sqrt(sum) == (int) Math.sqrt(sum); Math.sqrt(sum) == (int) Math.sqrt(sum) Math.sqrt(sum) Math.sqrt Math sum (int) Math.sqrt(sum) Math.sqrt Math sum int[] x1 x1 int[] x2 x2 public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}

	static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	}
} public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int D = s.nextInt();
			final int X[][] = new int[N][D];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					X[i][j] = s.nextInt();
				}
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}

	static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	}
} Main
import java.util.Scanner;

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

			int ret = 0;
			for (int i = 0; i < N; i++) {
				for (int j = i + 1; j < N; j++) {
					if (calc(X[i], X[j])) {
						ret++;
					}
				}
			}
			System.out.println(ret);
		}
	}

	static boolean calc(int[] x1, int[] x2) {
		int sum = 0;
		for (int i = 0; i < x1.length; i++) {
			sum += (x2[i] - x1[i]) * (x2[i] - x1[i]);
		}

		return Math.sqrt(sum) == (int) Math.sqrt(sum);
	}
}
