import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

} import java.io.PrintStream; PrintStream java.io import java.util.Scanner; Scanner java.util public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

} Main static final PrintStream out = System.out; out System.out System System.out static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static final long Mod = 1000_000_007L; Mod 1000_000_007L public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	} main {
		Main main = new Main();
		main.solve();
		System.exit(0);
	} Main main = new Main(); main new Main() main.solve() main.solve main System.exit(0) System.exit System 0 String[] args args void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	} solve {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	} int N = nextInt(); N nextInt() nextInt int D = nextInt(); D nextInt() nextInt int[][] space = new int[N][D]; space new int[N][D] N D for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			space[i]=nextIntArray(D);
		} {
			space[i]=nextIntArray(D);
		} space[i]=nextIntArray(D) space[i] space i nextIntArray(D) nextIntArray D int cnt = 0; cnt 0 for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		} int i=0; int i=0; i 0 i<N-1 i N-1 N 1 i++ i++ i {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		} {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		} for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			} {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			} double sum = 0; sum 0 for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				} int k=0; int k=0; k 0 k<D k D k++ k++ k {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				} {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				} sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]) sum Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]) Math.abs(space[i][k]-space[j][k]) Math.abs Math space[i][k]-space[j][k] space[i][k] space[i] space i k space[j][k] space[j] space j k Math.abs(space[i][k]-space[j][k]) Math.abs Math space[i][k]-space[j][k] space[i][k] space[i] space i k space[j][k] space[j] space j k double sqrt = Math.sqrt(sum); sqrt Math.sqrt(sum) Math.sqrt Math sum String S = String.valueOf(sqrt); S String.valueOf(sqrt) String.valueOf String sqrt if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				} S.indexOf(".0")==S.length()-2&&sqrt>0 S.indexOf(".0")==S.length()-2 S.indexOf(".0") S.indexOf S ".0" S.length()-2 S.length() S.length S 2 sqrt>0 sqrt 0 {
					cnt++;
					//out.println(S);
				} cnt++ cnt out.println(cnt) out.println out cnt public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	} nextIntArray {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	} int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++)a[i] = nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = nextInt(); a[i] = nextInt() a[i] a i nextInt() nextInt return a; a int n n public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	} nextLongArray {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	} long[] a = new long[n]; a new long[n] n for (int i = 0; i < n; i++)a[i] = nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = nextLong(); a[i] = nextLong() a[i] a i nextLong() nextLong return a; a int n n public int nextInt() {
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() {
		return Long.parseLong(next());
	} nextLong {
		return Long.parseLong(next());
	} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public String next() {
		return sc.next();
	} next {
		return sc.next();
	} return sc.next(); sc.next() sc.next sc public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

} public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

} Main
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int D = nextInt();
		int[][] space = new int[N][D];
		for(int i=0;i<N;i++) {
			space[i]=nextIntArray(D);
		}
		int cnt = 0;
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
					sum += Math.abs(space[i][k]-space[j][k])*Math.abs(space[i][k]-space[j][k]);
				}
				double sqrt = Math.sqrt(sum);

				String S = String.valueOf(sqrt);

				if(S.indexOf(".0")==S.length()-2&&sqrt>0) {
					cnt++;
					//out.println(S);
				}
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}