import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	} main {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	} try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		} catch (Exception e) {
			// TODO: handle exception
		} Exception e {
			// TODO: handle exception
		} {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n n d; d n = sc.nextInt() n sc.nextInt() sc.nextInt sc d = sc.nextInt() d sc.nextInt() sc.nextInt sc double[][] points = new double[n][d]; points new double[n][d] n d int counter = 0; counter 0 for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[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++) {
					points[i][j] = sc.nextInt();
					
				}
			} {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			} for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				} int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
					points[i][j] = sc.nextInt();
					
				} {
					points[i][j] = sc.nextInt();
					
				} points[i][j] = sc.nextInt() points[i][j] points[i] points i j sc.nextInt() sc.nextInt sc for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			} 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 total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			} {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			} for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				} {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				} double total = 0; total 0 for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					} int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					} {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					} double tmpTotal = Math.abs(points[i][k] - points[j][k]); tmpTotal Math.abs(points[i][k] - points[j][k]) Math.abs Math points[i][k] - points[j][k] points[i][k] points[i] points i k points[j][k] points[j] points j k total += Math.pow(tmpTotal, 2) total Math.pow(tmpTotal, 2) Math.pow Math tmpTotal 2 total = Math.sqrt(total) total Math.sqrt(total) Math.sqrt Math total int tmpTotal = (int) total; tmpTotal (int) total if (total == (double)tmpTotal) {
						counter++;
					} total == (double)tmpTotal total (double)tmpTotal {
						counter++;
					} counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n, d;
			
			n = sc.nextInt();
			d = sc.nextInt();
			
			double[][] points = new double[n][d];
			
			int counter = 0;
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < d; j++) {
					points[i][j] = sc.nextInt();
					
				}
			}
			
			for (int i = 0; i < n - 1; i++) {
				for (int j = i+1; j < n; j++) {
					
					double total = 0;
					for (int k = 0; k < d; k++) {
						double tmpTotal = Math.abs(points[i][k] - points[j][k]);
						total += Math.pow(tmpTotal, 2);
					}
					total = Math.sqrt(total);

					int tmpTotal = (int) total;
					
					
					if (total == (double)tmpTotal) {
						counter++;
					}
				}
			}
			
			System.out.println(counter);
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}
