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[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}
} 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[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					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[][] array = new int[n + 1][d + 1]; array new int[n + 1][d + 1] n + 1 n 1 d + 1 d 1 for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[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++) {
				array[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				array[i][j] = sc.nextInt();
			} {
				array[i][j] = sc.nextInt();
			} array[i][j] = sc.nextInt() array[i][j] array[i] array i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		} {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		} for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			} {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			} int norm = 0; norm 0 for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				} {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				} int diff = array[i][k] - array[j][k]; diff array[i][k] - array[j][k] array[i][k] array[i] array i k array[j][k] array[j] array j k norm += diff * diff norm diff * diff diff diff boolean flag = false; flag false for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				} int k = 0; int k = 0; k 0 k <= norm k norm k++ k++ k {
					if (k * k == norm) {
						flag = true;
					}
				} {
					if (k * k == norm) {
						flag = true;
					}
				} if (k * k == norm) {
						flag = true;
					} k * k == norm k * k k k norm {
						flag = true;
					} flag = true flag true if (flag == true) {
					ans++;
				} flag == true flag true {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}
} 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[][] array = new int[n + 1][d + 1];

		//入力値を配列に代入
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		
		//i < j の場合の全ての組み合わせで距離を計算する
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++ ) {
				int norm = 0;
				for (int k = 0; k < d; k++) {
					int diff = array[i][k] - array[j][k];
					norm += diff * diff;
				}
				//整数かどうかチェックする
				boolean flag = false;
				for (int k = 0; k <= norm; k++) {
					if (k * k == norm) {
						flag = true;
					}
				}
				if (flag == true) {
					ans++;
				}
			}
		}
		System.out.println(ans);

	}
}
