program bbb

implicit none
integer :: n, d, i, j, k, co
real :: r
integer, allocatable, dimension(:,:) :: x

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

co=0

do i=1,n
 do j=i+1,n
  r=0
  do k=1,d
  r=r+(x(k,i)-x(k,j))**2
  end do
 r=r**0.5
 if(r==int(r)) co=co+1
 end do
end do

write(*,'(i0)') co

end program