import java.util.Scanner;

public class Main{
	static long a;
	static long b;
	static long x;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	static long a;
	static long b;
	static long x;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main static long a; a static long b; b static long x; x public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan int[][] x = new int[n][d]; x new int[n][d] n d for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		} {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		} for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = scan.nextInt();
			} {
				x[i][j] = scan.nextInt();
			} x[i][j] = scan.nextInt() x[i][j] x[i] x i j scan.nextInt() scan.nextInt scan int ans = 0; ans 0 for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		} 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 temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		} {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		} for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			} {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			} double temp = 0.0; temp 0.0 for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				} {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				} temp += Math.pow((x[j][k] - x[i][k]), 2) temp Math.pow((x[j][k] - x[i][k]), 2) Math.pow Math (x[j][k] - x[i][k]) x[j][k] x[j] x j k x[i][k] x[i] x i k 2 temp = Math.pow(temp, 0.5) temp Math.pow(temp, 0.5) Math.pow Math temp 0.5 if(temp - (long)temp == 0.0) {
					ans++;
				} temp - (long)temp == 0.0 temp - (long)temp temp (long)temp 0.0 {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
	static long a;
	static long b;
	static long x;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} public class Main{
	static long a;
	static long b;
	static long x;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main{
	static long a;
	static long b;
	static long x;
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();

		int[][] x = new int[n][d];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				x[i][j] = scan.nextInt();
			}
		}

		int ans = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double temp = 0.0;
				for(int k = 0; k < d; k++) {
					temp += Math.pow((x[j][k] - x[i][k]), 2);
				}
				temp = Math.pow(temp, 0.5);
				if(temp - (long)temp == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}
