import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	}
} Main public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] ND = br.readLine().split(" "); ND br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int N = Integer.parseInt(ND[0]); N Integer.parseInt(ND[0]) Integer.parseInt Integer ND[0] ND 0 int D = Integer.parseInt(ND[1]); D Integer.parseInt(ND[1]) Integer.parseInt Integer ND[1] ND 1 int[][] TENi = new int[N][D]; TENi new int[N][D] N D for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		} {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		} String[] TEN = br.readLine().split(" "); TEN br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			} {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			} TENi[i][j] = Integer.parseInt(TEN[j]) TENi[i][j] TENi[i] TENi i j Integer.parseInt(TEN[j]) Integer.parseInt Integer TEN[j] TEN j for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		} {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		} for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				//System.out.print(TENi[i][j] + " ");
			} {
				//System.out.print(TENi[i][j] + " ");
			} double[][] sum = new double[N][N]; sum new double[N][N] N N for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		} int k = 0; int k = 0; k 0 k < N k N k++ k++ k {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		} {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		} for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			} {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			} for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				} {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				} sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2) sum[k][i] sum[k] sum k i Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2) Math.pow Math Math.abs(TENi[k][j] - TENi[i][j]) Math.abs Math TENi[k][j] - TENi[i][j] TENi[k][j] TENi[k] TENi k j TENi[i][j] TENi[i] TENi i j 2 sum[k][i] = Math.sqrt(sum[k][i]) sum[k][i] sum[k] sum k i Math.sqrt(sum[k][i]) Math.sqrt Math sum[k][i] sum[k] sum k i int count = 0; count 0 for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		} {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		} for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			} int j = 0; int j = 0; j 0 j < N j N j++ j++ j {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			} {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			} if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				} sum[i][j] % 1 == 0 && sum[i][j] != 0 sum[i][j] % 1 == 0 sum[i][j] % 1 sum[i][j] sum[i] sum i j 1 0 sum[i][j] != 0 sum[i][j] sum[i] sum i j 0 {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				} count++ count System.out.println(count / 2) System.out.println System.out System System.out count / 2 count 2 String[] args args public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	}
} public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] ND = br.readLine().split(" ");

		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);

		int[][] TENi = new int[N][D];

		for (int i = 0; i < N; i++) {

			String[] TEN = br.readLine().split(" ");

			for (int j = 0; j < D; j++) {
				TENi[i][j] = Integer.parseInt(TEN[j]);
			}

		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				//System.out.print(TENi[i][j] + " ");
			}
			//System.out.println();
		}

		double[][] sum = new double[N][N];

		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < D; j++) {
					sum[k][i] += Math.pow(Math.abs(TENi[k][j] - TENi[i][j]), 2);
				}
				sum[k][i] = Math.sqrt(sum[k][i]);
			}
		}

		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {

				if (sum[i][j] % 1 == 0 && sum[i][j] != 0) {
					//System.out.println(sum[i][j] + "は整数です");
					count++;
				}
			}
		}

		System.out.println(count / 2);
	}
}
