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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    }
} 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    }
} 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    } 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 ans = 0; ans 0 for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        } {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        } for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            } int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            } {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            } double dist = 0; dist 0 for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    dist += calc(x[i][k], x[j][k]);
                } {
                    dist += calc(x[i][k], x[j][k]);
                } dist += calc(x[i][k], x[j][k]) dist calc(x[i][k], x[j][k]) calc x[i][k] x[i] x i k x[j][k] x[j] x j k if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                } Math.sqrt(dist) % 1 == 0 Math.sqrt(dist) % 1 Math.sqrt(dist) Math.sqrt Math dist 1 0 {
                    ans++;
                } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    } calc {
        return Math.pow(Math.abs(i - j), 2);
    } return Math.pow(Math.abs(i - j), 2); Math.pow(Math.abs(i - j), 2) Math.pow Math Math.abs(i - j) Math.abs Math i - j i j 2 int i i int j j 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    }
} 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    }
} 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 ans = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                double dist = 0;
                for (int k = 0; k < d; k++) {
                    dist += calc(x[i][k], x[j][k]);
                }

                // 整数？
                if (Math.sqrt(dist) % 1 == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }

    private static double calc(int i, int j) {
        return Math.pow(Math.abs(i - j), 2);
    }
}
