
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	}
} Main public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	} 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 double X[][] = new double[N][D]; X new double[N][D] N D double ans = 0; ans 0 int count = 0; count 0 for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		} 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.nextDouble();
			}
		} {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		} for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = sc.nextDouble();
			} {
				X[i][j] = sc.nextDouble();
			} X[i][j] = sc.nextDouble() X[i][j] X[i] X i j sc.nextDouble() sc.nextDouble sc for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		} {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		} for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			} int k = i + 1; int k = i + 1; k i + 1 i 1 k < N k N k++ k++ k {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			} {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			} for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				} {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				} ans += Math.pow(X[i][j] - X[k][j], 2) ans Math.pow(X[i][j] - X[k][j], 2) Math.pow Math X[i][j] - X[k][j] X[i][j] X[i] X i j X[k][j] X[k] X k j 2 for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				} int l = 0; int l = 0; l 0 l * l <= ans l * l l l ans l++ l++ l {
					if (l * l == ans) {
						count++;
					}
				} {
					if (l * l == ans) {
						count++;
					}
				} if (l * l == ans) {
						count++;
					} l * l == ans l * l l l ans {
						count++;
					} count++ count ans = 0 ans 0 System.out.print(count) System.out.print System.out System System.out count String arg[] arg public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	}
} public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		double X[][] = new double[N][D];

		double ans = 0;
		int count = 0;

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextDouble();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int k = i + 1; k < N; k++) {
				for (int j = 0; j < D; j++) {
					ans += Math.pow(X[i][j] - X[k][j], 2);
				}

				for (int l = 0; l * l <= ans; l++) {
					if (l * l == ans) {
						count++;
					}
				}
				ans = 0;
			}
		}
		System.out.print(count);
	}
}