program abc133b
   implicit none
   integer :: n, d , i, j, counter
   double precision, allocatable :: x(:,:)
   double precision :: dist, diff

   read(*,*) n, d
   allocate(x(n,d) )

   do i = 1, n
      read(*,*) x(i,:)
   end do

   dist = 0.
   counter = 0
   diff = 0.

   do i = 1, n-1
      do j = i+1, n
         dist = dble(sum( (X(i,:) -X(j,:))**2 ) )
         dist = sqrt(dist)
         diff = abs(dist -dble(nint(dist) ))
         !print *, i, j, diff
         if ( diff == 0. .or. diff <= 1.e-12 ) then
            counter = counter + 1
         end if
      end do

   end do

   print *, counter



end program abc133b
