
import java.util.Scanner;

public class Main {

	static int n;
	static int d;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	static int n;
	static int d;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	}
} Main static int n; n static int d; d public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	} main {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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 ans = 0; ans 0 for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		} {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		} for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			} int j = i + 1 ; int j = i + 1 ; j i + 1 i 1 j < n j n j++ j++ j {
				if(judge(x[i], x[j])) {
					ans++;
				}
			} {
				if(judge(x[i], x[j])) {
					ans++;
				}
			} if(judge(x[i], x[j])) {
					ans++;
				} judge(x[i], x[j]) judge x[i] x i x[j] x j {
					ans++;
				} ans++ ans System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	} judge {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	} int sum = 0; sum 0 for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		} int i = 0 ; int i = 0 ; i 0 i < d i d i++ i++ i {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		} {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		} sum += (z[i] - y[i]) * (z[i] - y[i]) sum (z[i] - y[i]) * (z[i] - y[i]) (z[i] - y[i]) z[i] z i y[i] y i (z[i] - y[i]) z[i] z i y[i] y i double root = Math.sqrt((double)sum); root Math.sqrt((double)sum) Math.sqrt Math (double)sum int hoge = (int)root; hoge (int)root return root - hoge == 0.0d; root - hoge == 0.0d root - hoge root hoge 0.0d int[] y y int[] z z public class Main {

	static int n;
	static int d;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	}
} public class Main {

	static int n;
	static int d;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	}
} Main

import java.util.Scanner;

public class Main {

	static int n;
	static int d;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		n = sc.nextInt();
		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 ans = 0;
		for(int i = 0 ; i < n ; i++) {
			for(int j = i + 1 ; j < n ; j++) {
				if(judge(x[i], x[j])) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}

	private static boolean judge(int[] y, int[] z) {
		int sum = 0;
		for(int i = 0 ; i < d ; i++) {
			sum += (z[i] - y[i]) * (z[i] - y[i]);
		}
		double root = Math.sqrt((double)sum);
		int hoge = (int)root;
		return root - hoge == 0.0d;
	}
}
