import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
}
 import java.util.Scanner; Scanner 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 ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {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 ans =0; ans 0 Main main = new Main(); main new Main() int[][]list = new int[N][D]; list new int[N][D] N D for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				list[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++) {
				list[i][j]= sc.nextInt();
			}
		} {
			for (int j = 0; j < D; j++) {
				list[i][j]= sc.nextInt();
			}
		} for (int j = 0; j < D; j++) {
				list[i][j]= sc.nextInt();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				list[i][j]= sc.nextInt();
			} {
				list[i][j]= sc.nextInt();
			} list[i][j]= sc.nextInt() list[i][j] list[i] list i j sc.nextInt() sc.nextInt sc for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		} {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		} for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			} int j = i; int j = i; j i j < N j N j++ j++ j {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			} {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			} if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				} i==j i j {
					continue;
				} continue; {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				} long con =0; con 0 for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					} {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					} con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2) con Math.pow(Math.abs(list[i][k] - list[j][k]), 2) Math.pow Math Math.abs(list[i][k] - list[j][k]) Math.abs Math list[i][k] - list[j][k] list[i][k] list[i] list i k list[j][k] list[j] list j k 2 if (main.chkSquearNum(con)) {ans++;} main.chkSquearNum(con) main.chkSquearNum main con {ans++;} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	} chkSquearNum {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	} if (N<0) {
			throw new IllegalArgumentException();
		} N<0 N 0 {
			throw new IllegalArgumentException();
		} throw new IllegalArgumentException(); new IllegalArgumentException() double sqrtNum = Math.sqrt(N); sqrtNum Math.sqrt(N) Math.sqrt Math N return isLong(sqrtNum); isLong(sqrtNum) isLong sqrtNum long N N public boolean isLong(double N) {
		return (N == Math.floor(N));
	} isLong {
		return (N == Math.floor(N));
	} return (N == Math.floor(N)); (N == Math.floor(N)) N Math.floor(N) Math.floor Math N double N N public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans =0;
		Main main = new Main();

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

		for (int i = 0; i < N; i++) {
			for (int j = i; j < N; j++) {
				if (i==j) {
					continue;
				}else {
					long con =0;
					for (int k = 0; k < D; k++) {
						con+=Math.pow(Math.abs(list[i][k] - list[j][k]), 2);
					}
					if (main.chkSquearNum(con)) {ans++;}
				}
			}
		}

		System.out.println(ans);

	}

	public boolean chkSquearNum(long N) {
		if (N<0) {
			throw new IllegalArgumentException();
		}

		double sqrtNum = Math.sqrt(N);
		return isLong(sqrtNum);
	}

	public boolean isLong(double N) {
		return (N == Math.floor(N));
	}
}

