import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

	// 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	}

	// 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

	// 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	}

	// 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.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][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] = sc.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] = sc.nextInt();
			}
		} {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				X[i][j] = sc.nextInt();
			} {
				X[i][j] = sc.nextInt();
			} X[i][j] = sc.nextInt() X[i][j] X[i] X i j sc.nextInt() sc.nextInt sc 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++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					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++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			} {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			} int tmp = 0; tmp 0 for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				} {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				} int m = (int) Math.pow(X[i][k] - X[j][k], 2); m (int) Math.pow(X[i][k] - X[j][k], 2) Math.pow Math X[i][k] - X[j][k] X[i][k] X[i] X i k X[j][k] X[j] X j k 2 tmp += m tmp m if (isSquareNumber(tmp)) {
					ans++;
				} isSquareNumber(tmp) isSquareNumber tmp {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args // 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	} isSquareNumber {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	} double sqrtOfNumber = Math.sqrt(number); sqrtOfNumber Math.sqrt(number) Math.sqrt Math number return (isInteger(sqrtOfNumber)); (isInteger(sqrtOfNumber)) isInteger sqrtOfNumber int number number // 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	} isInteger {
			return (number == Math.floor(number));
	} return (number == Math.floor(number)); (number == Math.floor(number)) number Math.floor(number) Math.floor Math number double number number public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

	// 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	}

	// 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

	// 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	}

	// 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] X = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				X[i][j] = sc.nextInt();
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int tmp = 0;
				for (int k = 0; k < D; k++) {
					int m = (int) Math.pow(X[i][k] - X[j][k], 2);
					tmp += m;
				}
				if (isSquareNumber(tmp)) {
					ans++;
				}
			}
		}

		System.out.println(ans);
	}

	// 平方数かどうかを調べる。
	public static boolean isSquareNumber(int number) {
		double sqrtOfNumber = Math.sqrt(number);
		return (isInteger(sqrtOfNumber));
	}

	// 整数かどうかを調べる。
	public static boolean isInteger (double number) {
			return (number == Math.floor(number));
	}
}
