import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	} main {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] X = new int[n][d]; X new int[n][d] n d int idx_n; idx_n int idx_d; idx_d for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		} idx_n = 0; idx_n = 0 idx_n 0 idx_n < n idx_n n idx_n++ idx_n++ idx_n {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		} {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		} for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			} idx_d = 0; idx_d = 0 idx_d 0 idx_d < d idx_d d idx_d++ idx_d++ idx_d {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			} {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			} X[idx_n][idx_d] = Short.parseShort(sc.next()) X[idx_n][idx_d] X[idx_n] X idx_n idx_d Short.parseShort(sc.next()) Short.parseShort Short sc.next() sc.next sc int ans = 0; ans 0 int x1; x1 int x2; x2 double dist; dist double distInt; distInt for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		} x1 = 0; x1 = 0 x1 0 x1 < n - 1 x1 n - 1 n 1 x1++ x1++ x1 {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		} {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		} for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			} x2 = x1 + 1; x2 = x1 + 1 x2 x1 + 1 x1 1 x2 < n x2 n x2++ x2++ x2 {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			} {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			} dist = calcDist(X[x1], X[x2], d) dist calcDist(X[x1], X[x2], d) calcDist X[x1] X x1 X[x2] X x2 d distInt = Math.round(dist) distInt Math.round(dist) Math.round Math dist if (dist - distInt == 0.0) {
					++ans;
				} dist - distInt == 0.0 dist - distInt dist distInt 0.0 {
					++ans;
				} ++ans ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	} calcDist {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	} double dist = 0.0; dist 0.0 int dist2 = 0; dist2 0 int idx = 0; idx 0 for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		} idx = 0; idx = 0 idx 0 idx < d idx d idx++ idx++ idx {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		} {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		} dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]) dist2 (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]) (x1[idx] - x2[idx]) x1[idx] x1 idx x2[idx] x2 idx (x1[idx] - x2[idx]) x1[idx] x1 idx x2[idx] x2 idx dist = Math.sqrt((double) dist2) dist Math.sqrt((double) dist2) Math.sqrt Math (double) dist2 return dist; dist int[] x1 x1 int[] x2 x2 int d d public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] X = new int[n][d];
		int idx_n;
		int idx_d;
		for (idx_n = 0; idx_n < n; idx_n++) {
			for (idx_d = 0; idx_d < d; idx_d++) {
				X[idx_n][idx_d] = Short.parseShort(sc.next());
			}
		}

		int ans = 0;
		// 点x1とx2の(x1<x2)比較
		int x1;
		int x2;
		double dist;
		double distInt;
		for (x1 = 0; x1 < n - 1; x1++) {
			for (x2 = x1 + 1; x2 < n; x2++) {
				dist = calcDist(X[x1], X[x2], d);
				distInt = Math.round(dist);
				if (dist - distInt == 0.0) {
					++ans;
				}
			}
		}

		System.out.println(ans);

	}

	public static double calcDist(int[] x1, int[] x2, int d) {
		double dist = 0.0;
		int dist2 = 0;
		int idx = 0;

		for (idx = 0; idx < d; idx++) {
			dist2 += (x1[idx] - x2[idx]) * (x1[idx] - x2[idx]);
		}
		dist = Math.sqrt((double) dist2);

		return dist;
	}
}
