import java.util.Scanner;

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 i=0; i<N; i++){
			for(int j=0; j<D; j++){
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		}


		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util 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 i=0; i<N; i++){
			for(int j=0; j<D; j++){
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))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[][] 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 outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		}


		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int 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 outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))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[][] 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 outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		} int outi=0; int outi=0; outi 0 outi<N outi N outi++ outi++ outi {
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		} {
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		} for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			} int ini=outi+1; int ini=outi+1; ini outi+1 outi 1 ini<N ini N ini++ ini++ ini {
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			} {
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			} int dist = 0; dist 0 for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				} int j=0; int j=0; j 0 j<D j D j++ j++ j {
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				} {
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				} dist += Math.pow(x[outi][j] - x[ini][j], 2) dist Math.pow(x[outi][j] - x[ini][j], 2) Math.pow Math x[outi][j] - x[ini][j] x[outi][j] x[outi] x outi j x[ini][j] x[ini] x ini j 2 if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++; Math.sqrt(dist) == (int)Math.sqrt(dist) Math.sqrt(dist) Math.sqrt Math dist (int)Math.sqrt(dist) Math.sqrt Math dist ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.Scanner;

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 i=0; i<N; i++){
			for(int j=0; j<D; j++){
				x[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int outi=0; outi<N; outi++){
			for(int ini=outi+1; ini<N; ini++){
				int dist = 0;
				for(int j=0; j<D; j++){
					dist += Math.pow(x[outi][j] - x[ini][j], 2);
				}
				if(Math.sqrt(dist) == (int)Math.sqrt(dist))ans++;
			}
		}


		System.out.println(ans);
	}
}
