program main
integer :: x,y,z,m,n,i,j,k,d,c
real,allocatable :: p(:,:)
real :: a,b

c =0

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

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

write(*,*)c
contains

end program main