import java.util.HashSet;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    }
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner HashSet<Long> hashSet = new HashSet<>(); hashSet new HashSet<>() for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        } long i=0; long i=0; i 0 i<1000 i 1000 i++ i++ i {
            hashSet.add(i*i);
        } {
            hashSet.add(i*i);
        } hashSet.add(i*i) hashSet.add hashSet i*i i i int[][] vectors = new int[N][D]; vectors new int[N][D] N D for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        } {
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        } for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            } int j=0; int j=0; j 0 j<D j D j++ j++ j {
                vectors[i][j] = scanner.nextInt();
            } {
                vectors[i][j] = scanner.nextInt();
            } vectors[i][j] = scanner.nextInt() vectors[i][j] vectors[i] vectors i j scanner.nextInt() scanner.nextInt scanner long ans = 0; ans 0 for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    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++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        } {
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        } for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            } int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            } {
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            } long tmp = 0; tmp 0 for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                } int k=0; int k=0; k 0 k<D k D k++ k++ k {
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                } {
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                } tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) tmp (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) (vectors[i][k] - vectors[j][k]) vectors[i][k] vectors[i] vectors i k vectors[j][k] vectors[j] vectors j k (vectors[i][k] - vectors[j][k]) vectors[i][k] vectors[i] vectors i k vectors[j][k] vectors[j] vectors j k if(hashSet.contains(tmp)){
                    ans++;
                } hashSet.contains(tmp) hashSet.contains hashSet tmp {
                    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 scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    }
} Main
import java.util.HashSet;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();

        HashSet<Long> hashSet = new HashSet<>();

        for(long i=0; i<1000; i++){
            hashSet.add(i*i);
        }


        int[][] vectors = new int[N][D];

        for(int i=0; i<N; i++){
            for(int j=0; j<D; j++){
                vectors[i][j] = scanner.nextInt();
            }
        }

        long ans = 0;

        for(int i=0; i<N-1; i++){
            for(int j=i+1; j<N; j++){
                long tmp = 0;
                for(int k=0; k<D; k++){
                    tmp += (vectors[i][k] - vectors[j][k]) * (vectors[i][k] - vectors[j][k]) ;
                }

                if(hashSet.contains(tmp)){
                    ans++;
                }
            }
        }

        System.out.println(ans);

    }
}
