program main

  implicit none

  integer :: n, d, i, j, k, flag
  integer, allocatable, dimension ( :, : ) :: x
  real :: r, tmp

  read ( unit = *, fmt = * ) n, d

  allocate ( x ( 1:n, 1:d ) )

  do i = 1, n

     read ( unit = *, fmt = * ) x ( i, 1:d )

  end do

  flag = 0
  
  do i = 1, n

     do j = i + 1, n

        tmp = 0.d0

        do k = 1, d

           tmp = tmp + ( x ( i, k ) - x ( j, k ) )**2

        end do

        r = sqrt ( tmp )

        if ( abs ( real ( int (r) ) - r ) < 1.d-8 ) then

           flag = flag + 1

        end if

     end do

  end do

  print '(i0)', flag
  
  
end program main
