import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

		System.out.println(answer);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

		System.out.println(answer);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

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

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

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

		System.out.println(answer);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X[][] = new int[N][D];
		double dst = 0;
		int answer = 0;

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

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

		System.out.println(answer);
	}
}
