import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	}
} 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(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) 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 D = sc.nextInt(); D sc.nextInt() sc.nextInt sc double[][] point = new double[N][D]; point new double[N][D] N D for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		} {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		} for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			} int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
				point[i][j] = sc.nextDouble();
			} {
				point[i][j] = sc.nextDouble();
			} point[i][j] = sc.nextDouble() point[i][j] point[i] point i j sc.nextDouble() sc.nextDouble sc int cnt = 0; cnt 0 for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		} {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		} for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			} {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			} double dist = 0; dist 0 for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]); int k = 0; int k = 0; k 0 k < D k D k++ k++ k dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]); dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]) dist (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]) (point[i][k] - point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k (point[i][k] - point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k int dist_i = (int)Math.sqrt(dist); dist_i (int)Math.sqrt(dist) Math.sqrt Math dist if((int)dist == dist_i * dist_i) cnt++; (int)dist == dist_i * dist_i (int)dist dist_i * dist_i dist_i dist_i cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), D = sc.nextInt();
		double[][] point = new double[N][D];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < D; j++) {
				point[i][j] = sc.nextDouble();
			}
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				// dist (i, j)
				double dist = 0;
				for(int k = 0; k < D; k++) dist += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
				int dist_i = (int)Math.sqrt(dist);
				if((int)dist == dist_i * dist_i) cnt++;
			}
		}
		System.out.println(cnt);
	}
}
