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];

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

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						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 = 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 ans =0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
} 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];

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

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	} main {
		Scanner sc = new 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 ans =0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	} 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 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 ans =0; ans 0 for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						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 dis =0;

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

				int dis =0;

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

				int dis =0;

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

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			} {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			} int dis =0; dis 0 for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				} {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				} dis += (int) Math.pow(x[i][k]-x[j][k], 2) dis (int) 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 for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				} int k = 0; int k = 0; k 0 k < 200 k 200 k++ k++ k {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				} {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				} if (dis < Math.pow(k, 2)) {
						break;
					} dis < Math.pow(k, 2) dis Math.pow(k, 2) Math.pow Math k 2 {
						break;
					} break; if (dis == Math.pow(k, 2)) {
						ans++;
					} dis == Math.pow(k, 2) dis Math.pow(k, 2) Math.pow Math k 2 {
						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 = 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 ans =0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
} 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];

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

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						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 = 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 ans =0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {

				int dis =0;

				for (int k = 0; k < D; k++) {
					dis += (int) Math.pow(x[i][k]-x[j][k], 2);
				}
				for (int k = 0; k < 200; k++) {
					if (dis < Math.pow(k, 2)) {
						break;
					}
					if (dis == Math.pow(k, 2)) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}
