import java.util.Scanner;

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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

	static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	}

} import java.util.Scanner; Scanner 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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

	static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	}

} 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 i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		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 for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[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++) {
				x[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				x[i][j] = sc.nextInt();
			} {
				x[i][j] = sc.nextInt();
			} x[i][j] = sc.nextInt() x[i][j] x[i] x i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					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++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		} for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				if (dist(x[i], x[j])) {
					ans++;
				}
			} {
				if (dist(x[i], x[j])) {
					ans++;
				}
			} if (dist(x[i], x[j])) {
					ans++;
				} dist(x[i], x[j]) dist x[i] x i x[j] x j {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	} dist {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	} int dist = 0; dist 0 for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		} {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		} dist += (a[i] - b[i]) * (a[i] - b[i]) dist (a[i] - b[i]) * (a[i] - b[i]) (a[i] - b[i]) a[i] a i b[i] b i (a[i] - b[i]) a[i] a i b[i] b i if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		} (int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0 (int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist (int)Math.sqrt(dist) *(int)Math.sqrt(dist) (int)Math.sqrt(dist) Math.sqrt Math dist (int)Math.sqrt(dist) Math.sqrt Math dist dist 0 {
			return true;
		} return true; true {
			return false;
		} return false; false int a[] a int b[] b 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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

	static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	}

} 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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

	static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	}

} Main
import java.util.Scanner;

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];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (dist(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

	static public boolean dist(int a[], int b[]) {
		int dist = 0;
		for (int i = 0; i < a.length; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}
		if ((int)Math.sqrt(dist) *(int)Math.sqrt(dist) - dist == 0) {
			return true;
		} else {
			return false;
		}
	}

}