import java.util.Scanner;

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];
		for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		}
		int dis[] = new int[1000];
		int count=0;
		for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		}
		int number=0;
		for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		}
		System.out.println(number);

	}
} import java.util.Scanner; Scanner 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 X[][] = new int[n][d];
		for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		}
		int dis[] = new int[1000];
		int count=0;
		for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		}
		int number=0;
		for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		}
		System.out.println(number);

	}
} 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];
		for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		}
		int dis[] = new int[1000];
		int count=0;
		for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		}
		int number=0;
		for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		}
		System.out.println(number);

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int X[][] = new int[n][d];
		for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		}
		int dis[] = new int[1000];
		int count=0;
		for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		}
		int number=0;
		for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		}
		System.out.println(number);

	} 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 for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		} int y=0; int y=0; y 0 y<n y n y++ y++ y {
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		} {
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		} for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			} int x=0; int x=0; x 0 x<d x d x++ x++ x {
				X[y][x] = sc.nextInt();
			} {
				X[y][x] = sc.nextInt();
			} X[y][x] = sc.nextInt() X[y][x] X[y] X y x sc.nextInt() sc.nextInt sc int dis[] = new int[1000]; dis new int[1000] 1000 int count=0; count 0 for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		} int ya=0; int ya=0; ya 0 ya<n ya n ya++ ya++ ya {
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		} {
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		} for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			} int yb=ya+1; int yb=ya+1; yb ya+1 ya 1 yb<n yb n yb++ yb++ yb {
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			} {
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			} for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				} int x=0; int x=0; x 0 x<d x d x++ x++ x {
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				} {
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				} int tmp = X[ya][x] - X[yb][x]; tmp X[ya][x] - X[yb][x] X[ya][x] X[ya] X ya x X[yb][x] X[yb] X yb x dis[count] += (int)Math.pow(tmp,2) dis[count] dis count (int)Math.pow(tmp,2) Math.pow Math tmp 2 count++ count int number=0; number 0 for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		} int i=0; int i=0; i 0 i<count i count i++ i++ i {
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		} {
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		} for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			} int j=1; int j=1; j 1 j<200 j 200 j++ j++ j {
				if(dis[i]==j*j){
					number++;	
				}
				
			} {
				if(dis[i]==j*j){
					number++;	
				}
				
			} if(dis[i]==j*j){
					number++;	
				} dis[i]==j*j dis[i] dis i j*j j j {
					number++;	
				} number++ number System.out.println(number) System.out.println System.out System System.out number String args[] args
import java.util.Scanner;

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];
		for(int y=0;y<n;y++){
			for(int x=0;x<d;x++){
				X[y][x] = sc.nextInt();
			}
		}
		int dis[] = new int[1000];
		int count=0;
		for(int ya=0;ya<n;ya++){
			for(int yb=ya+1;yb<n;yb++){
				for(int x=0;x<d;x++){
					int tmp = X[ya][x] - X[yb][x];
					dis[count] += (int)Math.pow(tmp,2);
				}
				count++;
			}
		}
		int number=0;
		for(int i=0;i<count;i++){
			for(int j=1;j<200;j++){
				if(dis[i]==j*j){
					number++;	
				}
				
			}
		}
		System.out.println(number);

	}
}
