import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    }
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    }
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    } main {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int n n d; d n = s.nextInt() n s.nextInt() s.nextInt s d = s.nextInt() d s.nextInt() s.nextInt s int x[][] = new int[n][d]; x new int[n][d] n d for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt(); int j = 0; int j = 0; j 0 j < n j n j++ j++ j for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt(); for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt(); int i = 0; int i = 0; i 0 i < d i d i++ i++ i x[j][i] = s.nextInt(); x[j][i] = s.nextInt() x[j][i] x[j] x j i s.nextInt() s.nextInt s int cnt2 = 0; cnt2 0 for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		} {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		} for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			} {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			} int sum2 = 0; sum2 0 for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				} {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				} int c; c c = Math.abs(x[i][k] - x[j][k]) c Math.abs(x[i][k] - x[j][k]) Math.abs Math x[i][k] - x[j][k] x[i][k] x[i] x i k x[j][k] x[j] x j k c *= c c c sum2 += c sum2 c int ans = (int) Math.sqrt(sum2); ans (int) Math.sqrt(sum2) Math.sqrt Math sum2 double ans2 = Math.sqrt(sum2); ans2 Math.sqrt(sum2) Math.sqrt Math sum2 if (ans == ans2)cnt2++; ans == ans2 ans ans2 cnt2++ cnt2 System.out.println(cnt2) System.out.println System.out System System.out cnt2 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    }
} public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    }
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int n, d;
		n = s.nextInt();
		d = s.nextInt();
		int x[][] = new int[n][d];
		for (int j = 0; j < n; j++)
			for (int i = 0; i < d; i++)
				x[j][i] = s.nextInt();
		int cnt2 = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int sum2 = 0;
				for (int k = 0; k < d; k++) {
					int c;
					c = Math.abs(x[i][k] - x[j][k]);
					c *= c;
					sum2 += c;
				}
				int ans = (int) Math.sqrt(sum2);
				double ans2 = Math.sqrt(sum2);
				if (ans == ans2)cnt2++;
			}
		}
		System.out.println(cnt2);
    }
}