
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[][] x = new int[n][d];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	}
	
	static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	}

} 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[][] x = new int[n][d];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	}
	
	static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		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();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		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();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					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[][] 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 int count = 0; count 0 for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		} {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		} for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			} int j = i+1; int j = i+1; j i+1 i 1 j < n j n j++ j++ j {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			} {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			} if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				} isInteger(getDistance(x[i], x[j])) isInteger getDistance(x[i], x[j]) getDistance x[i] x i x[j] x j {
					count++;
				} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	} isInteger {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	} int f = (int)Math.floor(d); f (int)Math.floor(d) Math.floor Math d if(d-f > 0)return false;
		else return true; d-f > 0 d-f d f 0 return false; false return true; true double d d static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	} getDistance {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	} double d = 0; d 0 for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		} int i = 0; int i = 0; i 0 i < x1.length i x1.length x1 x1.length i++ i++ i {
			d += Math.pow(x1[i]-x2[i], 2);
		} {
			d += Math.pow(x1[i]-x2[i], 2);
		} d += Math.pow(x1[i]-x2[i], 2) d Math.pow(x1[i]-x2[i], 2) Math.pow Math x1[i]-x2[i] x1[i] x1 i x2[i] x2 i 2 return Math.sqrt(d); Math.sqrt(d) Math.sqrt Math d int[] x1 x1 int[] x2 x2 public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		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();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	}
	
	static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		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();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	}
	
	static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	}

} 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[][] x = new int[n][d];
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if(isInteger(getDistance(x[i], x[j]))) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
	
	static boolean isInteger(double d) {
		int f = (int)Math.floor(d);
		if(d-f > 0)return false;
		else return true;
	}
	
	static double getDistance(int[] x1, int[] x2) {
		double d = 0;
		for (int i = 0; i < x1.length; i++) {
			d += Math.pow(x1[i]-x2[i], 2);
		}
		return Math.sqrt(d);
	}

}
