import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	} c {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	} double dist = 0; dist 0 for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		} int i = 0; int i = 0; i 0 i < D i D 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 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist if (dist == (int) dist) {
			return true;
		} else {
			return false;
		} dist == (int) dist dist (int) dist {
			return true;
		} return true; true {
			return false;
		} return false; false int[] a a int[] b b int D D public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	} _main {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	} Scanner sc = new Scanner(in); sc new Scanner(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][]; X new int[N][] N for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			X[i] = nextIntArray(sc, D);
		} {
			X[i] = nextIntArray(sc, D);
		} X[i] = nextIntArray(sc, D) X[i] X i nextIntArray(sc, D) nextIntArray sc D sc.close() sc.close sc int ans = 0; ans 0 for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					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 (c(X[i], X[j], D)) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			} {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			} if (c(X[i], X[j], D)) {
					ans++;
				} c(X[i], X[j], D) c X[i] X i X[j] X j D {
					ans++;
				} ans++ ans out.println(ans) out.println out ans String[] args args public static void main(String[] args) {
		new Main()._main(args);
	} main {
		new Main()._main(args);
	} new Main()._main(args) new Main()._main new Main() args String[] args args @SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} nextIntArray {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	} int[] result = new int[n]; result new int[n] n for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			result[i] = sc.nextInt();
		} {
			result[i] = sc.nextInt();
		} result[i] = sc.nextInt() result[i] result i sc.nextInt() sc.nextInt sc return result; result Scanner sc sc int n n public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	private boolean c(int[] a, int[] b, int D) {
		double dist = 0;

		for (int i = 0; i < D; i++) {
			dist += (a[i] - b[i]) * (a[i] - b[i]);
		}

		dist = Math.sqrt(dist);
		if (dist == (int) dist) {
			return true;
		} else {
			return false;
		}
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][];
		for (int i = 0; i < N; i++) {
			X[i] = nextIntArray(sc, D);
		}

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (c(X[i], X[j], D)) {
					ans++;
				}
			}
		}
		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}
