import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    }
} Main public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    } main {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int D = Integer.parseInt(sc.next()); D Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int A[][] = new int[N][D]; A new int[N][D] N D for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[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++)
                A[i][j] =  Integer.parseInt(sc.next());
        } {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        } for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next()); int j=0; int j=0; j 0 j<D j D j++ j++ j A[i][j] =  Integer.parseInt(sc.next()); A[i][j] =  Integer.parseInt(sc.next()) A[i][j] A[i] A i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc int cnt = 0; cnt 0 long sum = 0; sum 0 for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        } {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        } for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            } int j=i+1; int j=i+1; j i+1 i 1 j<N j N j++ j++ j {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            } {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            } sum = 0 sum 0 for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                } int k=0; int k=0; k 0 k<D k D k++ k++ k {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                } {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                } sum += Math.pow(A[i][k]-A[j][k], 2) sum Math.pow(A[i][k]-A[j][k], 2) Math.pow Math A[i][k]-A[j][k] A[i][k] A[i] A i k A[j][k] A[j] A j k 2 int d1 = (int)Math.sqrt(sum); d1 (int)Math.sqrt(sum) Math.sqrt Math sum if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++; (int)sum==(int)Math.pow((double)d1, 2) (int)sum (int)Math.pow((double)d1, 2) Math.pow Math (double)d1 2 cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    }
}