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();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	}
} 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();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int d = scan.nextInt();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	} main {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int d = scan.nextInt();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	} 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 double[][] point = new double[n][d]; point new double[n][d] n d double[][] y = new double[n][d]; y new double[n][d] n d for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.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] = scan.nextDouble();
			}
		} {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		} for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				point[i][j] = scan.nextDouble();
			} {
				point[i][j] = scan.nextDouble();
			} point[i][j] = scan.nextDouble() point[i][j] point[i] point i j scan.nextDouble() scan.nextDouble scan int count = 0; count 0 for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		} 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 dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		} {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		} for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			} {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			} double dist = 0; dist 0 for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				} dist += Math.pow((point[i][k] - point[j][k]), 2) dist Math.pow((point[i][k] - point[j][k]), 2) Math.pow Math (point[i][k] - point[j][k]) point[i][k] point[i] point i k point[j][k] point[j] point j k 2 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist if(dist == Math.floor(dist)) {
					count++;
				} dist == Math.floor(dist) dist Math.floor(dist) Math.floor Math dist {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count 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();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int d = scan.nextInt();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	}
} 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();
		double[][] point = new double[n][d];
		double[][] y = new double[n][d];

		for(int i = 0; i < n; i++) {
			for(int j = 0; j < d; j++) {
				point[i][j] = scan.nextDouble();
			}
		}

		int count = 0;
		for(int i = 0; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				double dist = 0;
				for(int k = 0; k < d; k++) {
					dist += Math.pow((point[i][k] - point[j][k]), 2);
				}
				dist = Math.sqrt(dist);
				if(dist == Math.floor(dist)) {
					count++;
				}
			}
		}
		System.out.println(count);
 	}
}