import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	}
	
	boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} import java.util.*; util.* java public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	}
	
	boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int MOD = 1000000007; MOD 1000000007 final int MAX = Integer.MAX_VALUE; MAX Integer.MAX_VALUE Integer Integer.MAX_VALUE final long LMAX = Long.MAX_VALUE; LMAX Long.MAX_VALUE Long Long.MAX_VALUE void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	} doIt {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	} 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 cnt = 0; cnt 0 for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		} int l = 0; int l = 0; l 0 l < n l n l++ l++ l {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		} {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		} for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			} int r = l + 1; int r = l + 1; r l + 1 l 1 r < n r n r++ r++ r {
				if(isInt(x, d, l, r))cnt++;
			} {
				if(isInt(x, d, l, r))cnt++;
			} if(isInt(x, d, l, r))cnt++; isInt(x, d, l, r) isInt x d l r cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	} isInt {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	} double sum = 0; sum 0 for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		} int i = 0; int i = 0; i 0 i < d i d i++ i++ i {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		} {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		} sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]) sum (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]) (x[x1][i] - x[x2][i]) x[x1][i] x[x1] x x1 i x[x2][i] x[x2] x x2 i (x[x1][i] - x[x2][i]) x[x1][i] x[x1] x x1 i x[x2][i] x[x2] x x2 i sum = Math.sqrt(sum) sum Math.sqrt(sum) Math.sqrt Math sum return (sum == (int)sum)?true:false; (sum == (int)sum)?true:false (sum == (int)sum) sum (int)sum true false int[][] x x int d d int x1 x1 int x2 x2 public static void main(String[] args) {
		new Main().doIt();
	} main {
		new Main().doIt();
	} new Main().doIt() new Main().doIt new Main() String[] args args public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	}
	
	boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	}
	
	boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
} Main
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;

	void doIt() {
		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 cnt = 0;
		for(int l = 0; l < n; l++) {
			for(int r = l + 1; r < n; r++) {
				if(isInt(x, d, l, r))cnt++;
			}
		}
		System.out.println(cnt);
	}
	
	boolean isInt(int[][] x, int d, int x1, int x2) {
		double sum = 0;
		for(int i = 0; i < d; i++) {
			sum += (x[x1][i] - x[x2][i]) * (x[x1][i] - x[x2][i]);
		}
		sum = Math.sqrt(sum);
		return (sum == (int)sum)?true:false;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}
