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

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

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

		System.out.println(result);
	} main {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		int 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 result = 0;
		for (int i = 0; i < N; i++) {
			for (int k = i+1; k < N; k++) {
				int tmp = 0;
				for (int j = 0; j < D; j++) {
					tmp+= Math.pow(Math.abs(X[i][j] - X[k][j]),2);
				}
				if (Math.round(Math.sqrt(tmp)) == Math.sqrt(tmp)) {
					result++;
				}
			}
		}

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

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

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

		System.out.println(result);
	}
}