import java.util.Scanner;

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

class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num[][];
		int N = sc.nextInt();
		int D = sc.nextInt();
		num = new int[N][D];
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < D;j++) {
				num[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for(int i = 0;i < N - 1;i++) {
			for(int j = i + 1;j < N;j++) {
				double distance = 0;
				for(int k = 0 ; k < D ;k++) {
					distance += (num[i][k] - num[j][k]) * (num[i][k] - num[j][k]);
				}
				distance = Math.sqrt(distance);
				if(distance == (double)((int)(distance))) count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}