
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int dimension = sc.nextInt();
		int[][] X = new int[number][dimension];
		int cnt = 0;
		//データを配列に格納
		for(int i =0; i<number ;i++) {
			for(int j =0; j<dimension;j++) {
				X[i][j] = sc.nextInt();			
			}		
		}
		for(int i =0; i<number ;i++) {
			for(int j =i+1; j<number;j++) {
              		int distance =0;
				 for(int k =0;k<dimension;k++)	{
					 int work =Math.abs(X[i][k]-X[j][k]);
					 distance +=work*work;
				 }
				 boolean flag =false;
				 for(int k = 0;k<=distance ;k++) {
					 if(k*k == distance) {
						 //System.out.println(i);
						 //System.out.println(j);
                       flag =true;
					 }
				 }
				 if(flag== true) {
					++cnt;
				 }
			}		
		}
		System.out.println(cnt);

	}

}

/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