import 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
} import java.util.*; util.* java 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
} 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int D = sc.nextInt();
        int[][] X = new int[N][D];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    } 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 int cnt = 0; cnt 0 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(); 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] X[i] X i j sc.nextInt() sc.nextInt sc for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++; 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++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++; for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++; int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++; if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++; calcD(X[i], X[j], D) % 1 == 0 calcD(X[i], X[j], D) % 1 calcD(X[i], X[j], D) calcD X[i] X i X[j] X j D 1 0 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    } calcD {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    } int squared = 0; squared 0 for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2); int i = 0; int i = 0; i 0 i < D i D i++ i++ i squared += Math.pow(Math.abs(Y[i] - Z[i]), 2); squared += Math.pow(Math.abs(Y[i] - Z[i]), 2) squared Math.pow(Math.abs(Y[i] - Z[i]), 2) Math.pow Math Math.abs(Y[i] - Z[i]) Math.abs Math Y[i] - Z[i] Y[i] Y i Z[i] Z i 2 return Math.sqrt(squared); Math.sqrt(squared) Math.sqrt Math squared int[] Y Y int[] Z Z int D 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
} 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
} Main
import 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];
        int cnt = 0;

        for (int i = 0; i < N; i++)
            for (int j = 0; j < D; j++)
                X[i][j] = sc.nextInt();

        for (int i = 0; i < N - 1; i++)
            for (int j = i + 1; j < N; j++)
                if (calcD(X[i], X[j], D) % 1 == 0)
                    cnt++;

        System.out.println(cnt);

    }

    static double calcD(int[] Y, int[] Z, int D) {
        int squared = 0;
        for (int i = 0; i < D; i++)
            squared += Math.pow(Math.abs(Y[i] - Z[i]), 2);

        return Math.sqrt(squared);
    }
}
