import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	}
} 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();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	} 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[][] pointInfo = new int[n][d]; pointInfo new int[n][d] n d for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[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++) {
				pointInfo[i][j] = sc.nextInt();
			}
		} {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		} for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			} int j =0; int j =0; j 0 j <d j d j++ j++ j {
				pointInfo[i][j] = sc.nextInt();
			} {
				pointInfo[i][j] = sc.nextInt();
			} pointInfo[i][j] = sc.nextInt() pointInfo[i][j] pointInfo[i] pointInfo i j sc.nextInt() sc.nextInt sc int answer =0; answer 0 for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		} 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++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		} {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		} for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			} int j = i +1; int j = i +1; j i +1 i 1 j < n j n j++ j++ j {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			} {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			} int kyori = 0; kyori 0 for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				} int k =0; int k =0; k 0 k <d k d k++ k++ k {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				} {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				} kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]) kyori (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]) (pointInfo[j][k]- pointInfo[i][k]) pointInfo[j][k] pointInfo[j] pointInfo j k pointInfo[i][k] pointInfo[i] pointInfo i k (pointInfo[j][k]- pointInfo[i][k]) pointInfo[j][k] pointInfo[j] pointInfo j k pointInfo[i][k] pointInfo[i] pointInfo i k int l =1; l 1 while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				} l <=16000 l 16000 {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				} if(l * l == kyori) {
						answer++;
						break;
					} l * l == kyori l * l l l kyori {
						answer++;
						break;
					} answer++ answer break; l++ l System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] pointInfo = new int[n][d];
		for(int i =0;i <n;i++) {
			for(int j =0;j <d;j++) {
				pointInfo[i][j] = sc.nextInt();
			}
		}
		int answer =0;
		for(int i = 0; i < n-1;i++) {
			for(int j = i +1; j < n;j++) {
				int kyori = 0;
				for(int k =0;k <d;k++) {
					kyori += (pointInfo[j][k]- pointInfo[i][k]) * (pointInfo[j][k]- pointInfo[i][k]);
				}
				int l =1;
				while(l <=16000) {
					if(l * l == kyori) {
						answer++;
						break;
					}
					l++;
				}
			}
		}
		System.out.println(answer);
	}
}