import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    } main {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int a = scan.nextInt(); a scan.nextInt() scan.nextInt scan int b = scan.nextInt(); b scan.nextInt() scan.nextInt scan int ans=0; ans 0 double[][] x = new double[a][b]; x new double[a][b] a b for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        } int i=0; int i=0; i 0 i<a i a i++ i++ i {
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        } {
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        } for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            } int l=0; int l=0; l 0 l<b l b l++ l++ l {
                x[i][l]=scan.nextDouble();
            } {
                x[i][l]=scan.nextDouble();
            } x[i][l]=scan.nextDouble() x[i][l] x[i] x i l scan.nextDouble() scan.nextDouble scan for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        } int i=0; int i=0; i 0 i<a-1 i a-1 a 1 i++ i++ i {
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        } {
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        } for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            } int p=i+1; int p=i+1; p i+1 i 1 p<a p a p++ p++ p {
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            } {
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            } double e = 0; e 0 for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                } int l=0; int l=0; l 0 l<b l b l++ l++ l {
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                } {
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                } e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2) e Math.pow(Math.abs(x[i][l]-x[p][l]),2) Math.pow Math Math.abs(x[i][l]-x[p][l]) Math.abs Math x[i][l]-x[p][l] x[i][l] x[i] x i l x[p][l] x[p] x p l 2 if(Math.sqrt(e)%1==0)ans++; Math.sqrt(e)%1==0 Math.sqrt(e)%1 Math.sqrt(e) Math.sqrt Math e 1 0 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 a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int ans=0;
        double[][] x = new double[a][b];
        for(int i=0;i<a;i++){
            for(int l=0;l<b;l++){
                x[i][l]=scan.nextDouble();
            }
        }
        for(int i=0;i<a-1;i++){
            for(int p=i+1;p<a;p++){
                double e = 0;
                for(int l=0;l<b;l++){
                    e+=Math.pow(Math.abs(x[i][l]-x[p][l]),2);
                }
                if(Math.sqrt(e)%1==0)ans++;
            }
        }
        System.out.println(ans);
    }
}