import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set 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();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(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();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(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 Set<Integer>  set = new HashSet<Integer>(); set new HashSet<Integer>() for (int i=1;i<1000;i++) {
			set.add(i*i);
		} int i=1; int i=1; i 1 i<1000 i 1000 i++ i++ i {
			set.add(i*i);
		} {
			set.add(i*i);
		} set.add(i*i) set.add set i*i i i int count =0; count 0 int a[][] = new int[N][D]; a new int[N][D] N D for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[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++) {
				a[i][j] = sc.nextInt();
			}
		} {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		} for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			} int j=0; int j=0; j 0 j<D j D j++ j++ j {
				a[i][j] = sc.nextInt();
			} {
				a[i][j] = sc.nextInt();
			} a[i][j] = sc.nextInt() a[i][j] a[i] a i j sc.nextInt() sc.nextInt sc for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		} {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		} for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			} int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			} {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			} int temp =0; temp 0 for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				} int k=0; int k=0; k 0 k<D k D k++ k++ k {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				} {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				} temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]) temp (a[i][k]-a[j][k])*(a[i][k]-a[j][k]) (a[i][k]-a[j][k]) a[i][k] a[i] a i k a[j][k] a[j] a j k (a[i][k]-a[j][k]) a[i][k] a[i] a i k a[j][k] a[j] a j k if(set.contains(temp)) {
					count++;
				} set.contains(temp) set.contains set 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();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(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();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		Set<Integer>  set = new HashSet<Integer>();
		for (int i=1;i<1000;i++) {
			set.add(i*i);
		}
		int count =0;
		int a[][] = new int[N][D];
		for (int i=0;i<N;i++) {
			for (int j=0;j<D;j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int i=0;i<N;i++) {
			for (int j=i+1;j<N;j++) {
				int temp =0;
				for (int k=0;k<D;k++) {
					temp +=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
				}
				if(set.contains(temp)) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}