import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	}

	private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	}

	private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	}

	private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	}

	private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	} main {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	} Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) int n = in.nextInt(); n in.nextInt() in.nextInt in int d = in.nextInt(); d in.nextInt() in.nextInt in 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] = in.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] = in.nextInt(); for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt(); int j = 0; int j = 0; j 0 j < d j d j++ j++ j x[i][j] = in.nextInt(); x[i][j] = in.nextInt() x[i][j] x[i] x i j in.nextInt() in.nextInt in System.out.println(solve(x)) System.out.println System.out System System.out solve(x) solve x in.close() in.close in String[] args args private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	} solve {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	} int r = 0; r 0 for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++; int i = 0; int i = 0; i 0 i < x.length i x.length x x.length i++ i++ i for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++; for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++; int j = i + 1; int j = i + 1; j i + 1 i 1 j < x.length j x.length x x.length j++ j++ j if (isOk(x[i], x[j]))
					r++; if (isOk(x[i], x[j]))
					r++; isOk(x[i], x[j]) isOk x[i] x i x[j] x j r++ r return r; r int[][] x x private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	} isOk {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	} long r = 0; r 0 for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2); int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i r += Math.pow(a[i] - b[i], 2); r += Math.pow(a[i] - b[i], 2) r Math.pow(a[i] - b[i], 2) Math.pow Math a[i] - b[i] a[i] a i b[i] b i 2 long r2 = (long) Math.pow(r, 0.5); r2 (long) Math.pow(r, 0.5) Math.pow Math r 0.5 if (r2 * r2 == r)
			return true;
		else
			return false; r2 * r2 == r r2 * r2 r2 r2 r return true; true return false; false int[] a a int[] b b public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	}

	private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	}

	private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	}

	private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	}

	private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int d = in.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++)
				x[i][j] = in.nextInt();
		System.out.println(solve(x));
		in.close();
	}

	private static int solve(int[][] x) {
		int r = 0;
		for (int i = 0; i < x.length; i++)
			for (int j = i + 1; j < x.length; j++)
				if (isOk(x[i], x[j]))
					r++;
		return r;
	}

	private static boolean isOk(int[] a, int[] b) {
		long r = 0;
		for (int i = 0; i < a.length; i++)
			r += Math.pow(a[i] - b[i], 2);
		long r2 = (long) Math.pow(r, 0.5);
		if (r2 * r2 == r)
			return true;
		else
			return false;
	}
}
