import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int ans = count();
        System.out.println(ans);
    }

    static int count() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    }
    static int cntInt(int i, int idx, int[][] ret) {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        int ans = count();
        System.out.println(ans);
    }

    static int count() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    }
    static int cntInt(int i, int idx, int[][] ret) {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    }
} Main public static void main(String[] args) {
        int ans = count();
        System.out.println(ans);
    } main {
        int ans = count();
        System.out.println(ans);
    } int ans = count(); ans count() count System.out.println(ans) System.out.println System.out System System.out ans String[] args args static int count() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    } count {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int idx = sc.nextInt(); idx sc.nextInt() sc.nextInt sc int[][] ret = new int[n][idx]; ret new int[n][idx] n idx int ans = 0; ans 0 for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        } {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        } for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < idx j idx j++ j++ j {
                ret[i][j] = sc.nextInt();
            } {
                ret[i][j] = sc.nextInt();
            } ret[i][j] = sc.nextInt() ret[i][j] ret[i] ret i j sc.nextInt() sc.nextInt sc ans += cntInt(i, idx, ret) ans cntInt(i, idx, ret) cntInt i idx ret sc.close() sc.close sc return ans; ans static int cntInt(int i, int idx, int[][] ret) {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    } cntInt {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    } int cnt = 0; cnt 0 if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        } i > 0 i 0 {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        } for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            } int k = 0; int k = 0; k 0 k < i k i k++ k++ k {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            } {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            } double sum = 0; sum 0 for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	} int j = 0; int j = 0; j 0 j < idx j idx j++ j++ j {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	} {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	} sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2) sum Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2) Math.pow Math Math.abs(ret[i][j] - ret[k][j]) Math.abs Math ret[i][j] - ret[k][j] ret[i][j] ret[i] ret i j ret[k][j] ret[k] ret k j 2 double calc = Math.sqrt(sum); calc Math.sqrt(sum) Math.sqrt Math sum if (calc == Math.floor(calc)) {
                    cnt++;
                } calc == Math.floor(calc) calc Math.floor(calc) Math.floor Math calc {
                    cnt++;
                } cnt++ cnt return cnt; cnt int i i int idx idx int[][] ret ret
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int ans = count();
        System.out.println(ans);
    }

    static int count() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    }
    static int cntInt(int i, int idx, int[][] ret) {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    }
}