import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					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(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					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 d = scan.nextInt(); d scan.nextInt() scan.nextInt scan float[][] array = new float[n][d]; array new float[n][d] n d float root_inside; root_inside int count=0; count 0 for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			} for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				array[i][j] = scan.nextInt();
			} {
				array[i][j] = scan.nextInt();
			} array[i][j] = scan.nextInt() array[i][j] array[i] array i j scan.nextInt() scan.nextInt scan for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		} int i_kari = 0; int i_kari = 0; i_kari 0 i_kari < n - 1 i_kari n - 1 n 1 i_kari++ i_kari++ i_kari {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		} {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		} for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			} int i = i_kari + 1; int i = i_kari + 1; i i_kari + 1 i_kari 1 i < n i n i++ i++ i {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			} {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			} root_inside = 0 root_inside 0 for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				} {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				} root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2) root_inside Math.pow((array[i_kari][j] - array[i][j]), 2) Math.pow Math (array[i_kari][j] - array[i][j]) array[i_kari][j] array[i_kari] array i_kari j array[i][j] array[i] array i j 2 if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				} Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0 Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside)) Math.ceil(Math.sqrt(root_inside)) Math.ceil Math Math.sqrt(root_inside) Math.sqrt Math root_inside Math.floor(Math.sqrt(root_inside)) Math.floor Math Math.sqrt(root_inside) Math.sqrt Math root_inside 0 {
					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(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					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(), d = scan.nextInt();
		float[][] array = new float[n][d];
		float root_inside;
		int count=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < d; j++) {
				array[i][j] = scan.nextInt();
			}
		for (int i_kari = 0; i_kari < n - 1; i_kari++) {

			for (int i = i_kari + 1; i < n; i++) {
				root_inside = 0;
				for (int j = 0; j < d; j++) {
					root_inside += Math.pow((array[i_kari][j] - array[i][j]), 2);
				}
				if(Math.ceil(Math.sqrt(root_inside))-Math.floor(Math.sqrt(root_inside))==0){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}