import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    }
} Main public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    } main {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    } double eps = Math.pow(10, -10); eps Math.pow(10, -10) Math.pow Math 10 -10 10 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next 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] =  Integer.parseInt(sc.next());
            }
        } 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] =  Integer.parseInt(sc.next());
            }
        } {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        } for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            } int j = 0; int j = 0; j 0 j < d j d j++ j++ j {
                x[i][j] =  Integer.parseInt(sc.next());
            } {
                x[i][j] =  Integer.parseInt(sc.next());
            } x[i][j] =  Integer.parseInt(sc.next()) x[i][j] x[i] x i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc double dist = 0; dist 0 int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        } {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        } for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            } {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            } if (i == j) continue; i == j i j continue; dist = 0 dist 0 for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                } {
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                } dist += Math.pow((x[i][k] - x[j][k]), 2) dist Math.pow((x[i][k] - x[j][k]), 2) Math.pow Math (x[i][k] - x[j][k]) x[i][k] x[i] x i k x[j][k] x[j] x j k 2 dist = Math.sqrt(dist) dist Math.sqrt(dist) Math.sqrt Math dist if ((dist - (int)dist) < eps) {
                    count++;
                } (dist - (int)dist) < eps (dist - (int)dist) dist (int)dist eps {
                    count++;
                } count++ count System.out.println(count/2) System.out.println System.out System System.out count/2 count 2 String[] args args public class Main {

    public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    }
} public class Main {

    public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        double eps = Math.pow(10, -10);


        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] =  Integer.parseInt(sc.next());
            }
        }


        double dist = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;

                dist = 0;

                for (int k = 0; k < d; k++){
                    dist += Math.pow((x[i][k] - x[j][k]), 2);
                }

                dist = Math.sqrt(dist);
                if ((dist - (int)dist) < eps) {
                    count++;
                }
            }
        }

        System.out.println(count/2);
    }
}