import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    }

} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    }

} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    } main {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] values = scanner.nextLine().split(" "); values scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int N = Integer.parseInt(values[0]); N Integer.parseInt(values[0]) Integer.parseInt Integer values[0] values 0 int D = Integer.parseInt(values[1]); D Integer.parseInt(values[1]) Integer.parseInt Integer values[1] values 1 List<List<Integer>> list = new ArrayList(); list new ArrayList() for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        } {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        } String[] points = scanner.nextLine().split(" "); points scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " List<Integer> pointList = new ArrayList(); pointList new ArrayList() for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                pointList.add(Integer.parseInt(points[j]));
            } {
                pointList.add(Integer.parseInt(points[j]));
            } pointList.add(Integer.parseInt(points[j])) pointList.add pointList Integer.parseInt(points[j]) Integer.parseInt Integer points[j] points j list.add(pointList) list.add list pointList int answer = 0; answer 0 for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        } int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        } {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        } List<Integer> current = list.get(i); current list.get(i) list.get list i for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            } {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            } List<Integer> target = list.get(j); target list.get(j) list.get list j double sum = 0; sum 0 for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                } {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                } double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k)); pow (target.get(k) - current.get(k)) * (target.get(k) - current.get(k)) (target.get(k) - current.get(k)) target.get(k) target.get target k current.get(k) current.get current k (target.get(k) - current.get(k)) target.get(k) target.get target k current.get(k) current.get current k sum = sum + pow sum sum + pow sum pow double distance = Math.sqrt(sum); distance Math.sqrt(sum) Math.sqrt Math sum int x = (int) distance; x (int) distance if ((x - distance) == 0.0) {
                    answer++;
                } (x - distance) == 0.0 (x - distance) x distance 0.0 {
                    answer++;
                } answer++ answer System.out.println(answer) System.out.println System.out System System.out answer scanner.close() scanner.close scanner String[] args args public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    }

} public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    }

} Main
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String[] values = scanner.nextLine().split(" ");
        int N = Integer.parseInt(values[0]);
        int D = Integer.parseInt(values[1]);
        List<List<Integer>> list = new ArrayList();

        for (int i = 0; i < N; i++) {
            String[] points = scanner.nextLine().split(" ");
            List<Integer> pointList = new ArrayList();

            for (int j = 0; j < D; j++) {
                pointList.add(Integer.parseInt(points[j]));
            }

            list.add(pointList);
        }

        int answer = 0;

        for (int i = 0; i < N - 1; i++) {

            List<Integer> current = list.get(i);
        

            for (int j = i + 1; j < N; j++) {

                List<Integer> target = list.get(j);

                double sum = 0;
                for (int k = 0; k < D; k++) {
                    double pow = (target.get(k) - current.get(k)) * (target.get(k) - current.get(k));
                    sum = sum + pow;

                }

                double distance = Math.sqrt(sum);
        

                int x = (int) distance;
                if ((x - distance) == 0.0) {
                    answer++;
                }
            }

        }

        System.out.println(answer);

        scanner.close();

    }

}