import 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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java 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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		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 n d int distanceBase = 0; distanceBase 0 double distance = 0; distance 0 int ans = 0; ans 0 for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n*d i n*d n d i++ i++ i {
			x[i] = sc.nextInt();
		} {
			x[i] = sc.nextInt();
		} x[i] = sc.nextInt() x[i] x i sc.nextInt() sc.nextInt sc for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		} {
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		} for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			} int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			} {
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			} for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				} int k=0; int k=0; k 0 k<d k d k++ k++ k {
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				} {
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				} distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]) distanceBase (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]) (x[i*d+k]-x[j*d+k]) x[i*d+k] x i*d+k i*d i d k x[j*d+k] x j*d+k j*d j d k (x[i*d+k]-x[j*d+k]) x[i*d+k] x i*d+k i*d i d k x[j*d+k] x j*d+k j*d j d k distance = Math.sqrt(distanceBase) distance Math.sqrt(distanceBase) Math.sqrt Math distanceBase if(distance - (int) distance == 0.0){
					ans ++;
				} distance - (int) distance == 0.0 distance - (int) distance distance (int) distance 0.0 {
					ans ++;
				} ans ++ ans distanceBase = 0 distanceBase 0 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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		System.out.println(ans);
	}
} Main
import 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];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		System.out.println(ans);
	}
}