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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
} 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
} 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	} 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	} 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 int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		} {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		} for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			} {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			} int sum = 0; sum 0 for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				} int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				} {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				} sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) sum (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				} int k = 0; int k = 0; k 0 k * k <= sum k * k k k sum k++ k++ k {
					if (k * k == sum) {
						cnt++;
					}
				} {
					if (k * k == sum) {
						cnt++;
					}
				} if (k * k == sum) {
						cnt++;
					} k * k == sum k * k k k sum {
						cnt++;
					} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
} 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
} 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();
			}
		}
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]); 
				}
				for (int k = 0; k * k <= sum; k++) {
					if (k * k == sum) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}
