import java.util.Scanner;

public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}
 import java.util.Scanner; Scanner java.util public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    } solve {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(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[][] points = new int[N][D]; points new int[N][D] N D for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[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++) {
                points[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < D j D j++ j++ j {
                points[i][j] = sc.nextInt();
            } {
                points[i][j] = sc.nextInt();
            } points[i][j] = sc.nextInt() points[i][j] points[i] points i j sc.nextInt() sc.nextInt sc int ans = 0; ans 0 for (int i = 0; i < N - 1; i++) {
            for (int j = i + 1; j < N; j++) {

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        } 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++) {

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            } 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 k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            } {

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            } int sum = 0; sum 0 for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                } int k = 0; int k = 0; k 0 k < D k D k++ k++ k {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                } {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                } sum += Math.pow(points[i][k] - points[j][k], 2) sum Math.pow(points[i][k] - points[j][k], 2) Math.pow Math points[i][k] - points[j][k] points[i][k] points[i] points i k points[j][k] points[j] points j k 2 double distance = Math.sqrt(sum); distance Math.sqrt(sum) Math.sqrt Math sum double flooredDistance = Math.floor(distance); flooredDistance Math.floor(distance) Math.floor Math distance if (distance == flooredDistance) {
                    ans++;
                } distance == flooredDistance distance flooredDistance {
                    ans++;
                } ans++ ans System.out.print(ans) System.out.print System.out System System.out ans // Main
    public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.Scanner;

public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] points = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                points[i][j] = sc.nextInt();
            }
        }

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

                int sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.pow(points[i][k] - points[j][k], 2);
                }
                double distance = Math.sqrt(sum);
                //int distanceInt = (int)distance;
                double flooredDistance = Math.floor(distance);
                if (distance == flooredDistance) {
                    ans++;
                }

            }
        }
        System.out.print(ans);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

