import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

} Main public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    } main {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    } try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        } {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int[] array = readIntArray(reader); array readIntArray(reader) readIntArray reader int N = array[0]; N array[0] array 0 int D = array[1]; D array[1] array 1 int[][] X = new int[N][]; X new int[N][] N for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                X[i] = readIntArray(reader);
            } {
                X[i] = readIntArray(reader);
            } X[i] = readIntArray(reader) X[i] X i readIntArray(reader) readIntArray reader int ret = 0; ret 0 for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            } {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            } for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                } {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                } int sum = 0; sum 0 for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    } int d = 0; int d = 0; d 0 d < D d D d++ d++ d {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    } {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    } sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]) sum (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]) (X[i][d] - X[j][d]) X[i][d] X[i] X i d X[j][d] X[j] X j d (X[i][d] - X[j][d]) X[i][d] X[i] X i d X[j][d] X[j] X j d double dist = Math.sqrt(sum); dist Math.sqrt(sum) Math.sqrt Math sum if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    } Math.abs(dist - Math.round(dist)) < 0.00000001 Math.abs(dist - Math.round(dist)) Math.abs Math dist - Math.round(dist) dist Math.round(dist) Math.round Math dist 0.00000001 {
                        ret++;
                    } ret++ ret System.out.println(ret) System.out.println System.out System System.out ret String[] args args public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    } readIntArray {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    } String[] str = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " int[] array = new int[str.length]; array new int[str.length] str.length str str.length for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        } int i = 0; int i = 0; i 0 i < str.length i str.length str str.length i++ i++ i {
            array[i] = Integer.parseInt(str[i]);
        } {
            array[i] = Integer.parseInt(str[i]);
        } array[i] = Integer.parseInt(str[i]) array[i] array i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i return array; array BufferedReader reader reader public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int[] array = readIntArray(reader);
            int N = array[0];
            int D = array[1];
            int[][] X = new int[N][];
            for (int i = 0; i < N; i++) {
                X[i] = readIntArray(reader);
            }

            int ret = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    int sum = 0;
                    for (int d = 0; d < D; d++) {
                        sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
                    }

                    double dist = Math.sqrt(sum);
                    if (Math.abs(dist - Math.round(dist)) < 0.00000001) {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }

    public static int[] readIntArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        int[] array = new int[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Integer.parseInt(str[i]);
        }
        return array;
    }

}
