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[][] X = new int[N][D];
		for ( int n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}

	public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	}

} 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[][] X = new int[N][D];
		for ( int n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}

	public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	}

} 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 n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					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 n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					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 n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		} int n = 0 ; int n = 0 ; n 0 n < N n N n++ n++ n {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		} {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		} for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			} int d = 0 ; int d = 0 ; d 0 d < D d D d++ d++ d {
				X[n][d] = sc.nextInt();
			} {
				X[n][d] = sc.nextInt();
			} X[n][d] = sc.nextInt() X[n][d] X[n] X n d 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 sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					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 sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		} {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		} for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			} int j = i + 1 ; int j = i + 1 ; j i + 1 i 1 j < N j N j++ j++ j {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			} {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			} int sqSum = squareSum(X[i], X[j]); sqSum squareSum(X[i], X[j]) squareSum X[i] X i X[j] X j int sqrt = (int) Math.round(Math.sqrt(sqSum)); sqrt (int) Math.round(Math.sqrt(sqSum)) Math.round Math Math.sqrt(sqSum) Math.sqrt Math sqSum if ( sqrt * sqrt == sqSum ) {
					cnt++;
				} sqrt * sqrt == sqSum sqrt * sqrt sqrt sqrt sqSum {
					cnt++;
				} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	} squareSum {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	} int sum = 0; sum 0 for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		} int d = 0 ; int d = 0 ; d 0 d < a.length d a.length a a.length d++ d++ d {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		} {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		} sum += (a[d] - b[d]) * (a[d] - b[d]) sum (a[d] - b[d]) * (a[d] - b[d]) (a[d] - b[d]) a[d] a d b[d] b d (a[d] - b[d]) a[d] a d b[d] b d return sum; sum int[] a a int[] b b 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 n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}

	public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	}

} 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 n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}

	public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	}

} 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[][] X = new int[N][D];
		for ( int n = 0 ; n < N ; n++ ) {
			for ( int d = 0 ; d < D ; d++ ) {
				X[n][d] = sc.nextInt();
			}
		}

		int cnt = 0;
		for ( int i = 0 ; i < N ; i++ ) {
			for ( int j = i + 1 ; j < N ; j++ ) {
				int sqSum = squareSum(X[i], X[j]);
				int sqrt = (int) Math.round(Math.sqrt(sqSum));
				if ( sqrt * sqrt == sqSum ) {
					cnt++;
				}
			}
		}

		System.out.println(cnt);
	}

	public static int squareSum(int[] a, int[] b) {
		int sum = 0;
		for ( int d = 0 ; d < a.length ; d++ ) {
			sum += (a[d] - b[d]) * (a[d] - b[d]);
		}
		return sum;
	}

}
