implicit none
integer :: n,d
integer,allocatable :: x(:,:),dx(:)
integer :: i,j,k,z

read *,n,d
allocate(x(d,n))
do i = 1, n
   read *,(x(j,i),j=1,d)
enddo

allocate(dx(d))

k = 0
do i = 1, n-1
   do j = i+1, n
      dx(:) = x(:,i) - x(:,j)
      z = dot_product(dx,dx)
      if (z == int(sqrt(real(z,kind=8)))**2) then
         k = k + 1
      endif
   enddo
enddo

print '(i0)',k
end