import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] points=new int [N][D];
		int count=0;

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

		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		}
		System.out.print(count);
	}
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] points=new int [N][D];
		int count=0;

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

		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		}
		System.out.print(count);
	}
} Main public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] points=new int [N][D];
		int count=0;

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

		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		}
		System.out.print(count);
	} main {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] points=new int [N][D];
		int count=0;

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

		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		}
		System.out.print(count);
	} 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[][] points=new int [N][D]; points new int [N][D] N D int count=0; count 0 for(int i=0;i<N;i++){
			for(int j=0;j<D;j++){
				points[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++){
				points[i][j]=sc.nextInt();
			}
		} {
			for(int j=0;j<D;j++){
				points[i][j]=sc.nextInt();
			}
		} for(int j=0;j<D;j++){
				points[i][j]=sc.nextInt();
			} int j=0; int j=0; j 0 j<D j D j++ j++ j {
				points[i][j]=sc.nextInt();
			} {
				points[i][j]=sc.nextInt();
			} points[i][j]=sc.nextInt() points[i][j] points[i] points i j sc.nextInt() sc.nextInt sc for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		} {
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		} for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			} {
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			} int sum=0; sum 0 for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				} int k=0; int k=0; k 0 k<D k D k++ k++ k {
					sum+=Math.pow(points[i][k]-points[j][k],2);
				} {
					sum+=Math.pow(points[i][k]-points[j][k],2);
				} sum+=Math.pow(points[i][k]-points[j][k],2) sum Math.pow(points[i][k]-points[j][k],2) Math.pow Math points[i][k]-points[j][k] points[i][k] points[i] points i k points[j][k] points[j] points j k 2 double distance=Math.sqrt(sum); distance Math.sqrt(sum) Math.sqrt Math sum double flooredDistance=Math.floor(distance); flooredDistance Math.floor(distance) Math.floor Math distance if(distance==flooredDistance){
					count++;
				} distance==flooredDistance distance flooredDistance {
					count++;
				} count++ count System.out.print(count) System.out.print System.out System System.out count String[] args args
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] points=new int [N][D];
		int count=0;

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

		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
			
				int sum=0;
				for(int k=0;k<D;k++){
					sum+=Math.pow(points[i][k]-points[j][k],2);
				}
				double distance=Math.sqrt(sum);
			
				double flooredDistance=Math.floor(distance);
				if(distance==flooredDistance){
					count++;
				}
			}
		}
		System.out.print(count);
	}
}