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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	}
} 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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	}
} 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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	} main {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());

		int[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	} 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[][] num = new int[n][d]; num new int[n][d] n d double pos = 0.0; pos 0.0 int count = 0; count 0 for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		} {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		} for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				num[i][j] = Integer.parseInt(sc.next());
			} {
				num[i][j] = Integer.parseInt(sc.next());
			} num[i][j] = Integer.parseInt(sc.next()) num[i][j] num[i] num i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		} {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		} for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			} int k = i + 1; int k = i + 1; k i + 1 i 1 k < n k n k++ k++ k {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			} {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			} pos = 0.0 pos 0.0 double tmp = 0.0; tmp 0.0 for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				} {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				} tmp = Math.abs(num[i][j] - num[k][j]) tmp Math.abs(num[i][j] - num[k][j]) Math.abs Math num[i][j] - num[k][j] num[i][j] num[i] num i j num[k][j] num[k] num k j tmp *= tmp tmp tmp pos += tmp pos tmp if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				} Math.sqrt(pos) % 1.0 == 0.0 Math.sqrt(pos) % 1.0 Math.sqrt(pos) Math.sqrt Math pos 1.0 0.0 {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args 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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	}
} 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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	}
} 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[][] num = new int[n][d];
		double pos = 0.0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				num[i][j] = Integer.parseInt(sc.next());
			}
		}

		for (int i = 0; i < n - 1; i++) {
			for (int k = i + 1; k < n; k++) {
				pos = 0.0;
				double tmp = 0.0;
				for (int j = 0; j < d; j++) {
					tmp = Math.abs(num[i][j] - num[k][j]);
					tmp *= tmp;
					pos += tmp;
				}
				if (Math.sqrt(pos) % 1.0 == 0.0) {
					count++;
				}
			}
		}

		System.out.println(count);

	}
}