program main
integer :: n,i,j,d,c
real(8),allocatable :: p(:,:)
real(8) :: a,b

c=0

read(*,*)n,d
allocate(p(n,d))
do i = 1,n
read(*,*)(p(i,j),j=1,d)
end do

do i = 1,n-2
do j = i+1,n
a = dsqrt(sum((p(i,:) - p(j,:))**2))
b = int(a)
if (a /= b) c=c+1
end do
end do

write(*,*)c

end program main