import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	} main {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan 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] = scan.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] = scan.nextInt();
			}
		} {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		} for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			} int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
				X[n][d] = scan.nextInt();
			} {
				X[n][d] = scan.nextInt();
			} X[n][d] = scan.nextInt() X[n][d] X[n] X n d scan.nextInt() scan.nextInt scan scan.close() scan.close scan int res = 0; res 0 for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		} int y=0; int y=0; y 0 y<N y N y++ y++ y {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		} {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		} for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			} int z=y+1; int z=y+1; z y+1 y 1 z<N z N z++ z++ z {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			} {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			} double distance2 = 0; distance2 0 for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				} int d=0; int d=0; d 0 d<D d D d++ d++ d {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				} {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				} int yy = X[y][d]; yy X[y][d] X[y] X y d int xx = X[z][d]; xx X[z][d] X[z] X z d distance2+= Math.pow(X[y][d] - X[z][d], 2) distance2 Math.pow(X[y][d] - X[z][d], 2) Math.pow Math X[y][d] - X[z][d] X[y][d] X[y] X y d X[z][d] X[z] X z d 2 if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				} Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2)) Math.sqrt(distance2) Math.sqrt Math distance2 Math.floor(Math.sqrt(distance2)) Math.floor Math Math.sqrt(distance2) Math.sqrt Math distance2 {
					res++;
				} res++ res System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int D = scan.nextInt();
		int[][] X = new int[N][D];

		for (int n = 0; n < N; n++) {
			for (int d = 0; d < D; d++) {
				X[n][d] = scan.nextInt();
			}
		}
		scan.close();

		int res = 0;

		for(int y=0; y<N; y++) {
			for(int z=y+1; z<N; z++) {
				double distance2 = 0;
				for(int d=0; d<D; d++) {
					int yy = X[y][d];
					int xx = X[z][d];
					distance2+= Math.pow(X[y][d] - X[z][d], 2);
				}
				if(Math.sqrt(distance2) == Math.floor(Math.sqrt(distance2))) {
					res++;
				}
			}
		}
		System.out.println(res);
	}

}