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 ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz