import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    } main {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int d=scan.nextInt(); d scan.nextInt() scan.nextInt scan int x[][]=new int[n][d]; x new int[n][d] n d int ans=0; ans 0 double c; c for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        } {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        } for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                x[i][k] = scan.nextInt();
            } {
                x[i][k] = scan.nextInt();
            } x[i][k] = scan.nextInt() x[i][k] x[i] x i k scan.nextInt() scan.nextInt scan for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        } {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        } for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            } int h=i+1; int h=i+1; h i+1 i 1 h<n h n h++ h++ h {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            } {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            } c=0 c 0 for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                } int k = 0; int k = 0; k 0 k < d k d k++ k++ k {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                } {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                } c+=Math.pow(x[i][k]-x[h][k],2) c Math.pow(x[i][k]-x[h][k],2) Math.pow Math x[i][k]-x[h][k] x[i][k] x[i] x i k x[h][k] x[h] x h k 2 c=Math.sqrt(c) c Math.sqrt(c) Math.sqrt Math c if(c%1.0==0){
                    ans++;
                } c%1.0==0 c%1.0 c 1.0 0 {
                    ans++;
                } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int x[][]=new int[n][d];
        int ans=0;
        double c;

        for(int i=0;i<n;i++) {
            for (int k = 0; k < d; k++) {
                x[i][k] = scan.nextInt();
            }
        }

        for(int i=0;i<n;i++) {
            for(int h=i+1;h<n;h++) {
//                if(i==h){continue; }
                c=0;
                for (int k = 0; k < d; k++) {
                    c+=Math.pow(x[i][k]-x[h][k],2);
//                    System.out.println(c);
                }
                c=Math.sqrt(c);
//                System.out.println(c);
                if(c%1.0==0){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }
}
