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 count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
} 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 count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	} 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 count = 0; count 0 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 for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		} {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		} for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			} int l = i+1; int l = i+1; l i+1 i 1 l < n l n l++ l++ l {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			} {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			} int temp = 0; temp 0 for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			} {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			} temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]) temp (x[i][j]-x[l][j])*(x[i][j]-x[l][j]) (x[i][j]-x[l][j]) x[i][j] x[i] x i j x[l][j] x[l] x l j (x[i][j]-x[l][j]) x[i][j] x[i] x i j x[l][j] x[l] x l j for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			} int k = 0; int k = 0; k 0 k <= Math.sqrt(temp) k Math.sqrt(temp) Math.sqrt Math temp k++ k++ k {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			} {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			} int judge = k*k; judge k*k k k if(judge==temp) {
					count++;

				} judge==temp judge temp {
					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 sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
} 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 count = 0;
		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();
			}
		}
		for(int i = 0; i < n-1; i++) {
			
			for(int l = i+1; l < n; l++) {
				int temp = 0;
			for(int j = 0; j < d; j++) {
				temp+=(x[i][j]-x[l][j])*(x[i][j]-x[l][j]);
			}
			for(int k = 0; k <= Math.sqrt(temp); k++) {
				int judge = k*k;
				if(judge==temp) {
					count++;

				}
			}
			}
		}
		System.out.println(count);
	}
}
