program main
 implicit none
 integer*8 N,D,i,j,k,cnt
 real*8 dist
 real*8, allocatable::X(:,:)
 read(*,*) N,D
 allocate( X(1:N,1:D) )
 do i=1,N
   read(*,*) X(i,:)
 end do
 cnt = 0
 do i=1,N-1
  do j=i+1,N
   dist = 0.0D0
   do k=1,D
    dist = dist + (X(i,k) - X(j,k))**2
   end do
   dist = sqrt(dist)
   !write(*,*) i,j,dist
   if(dist - floor(dist) == 0) then
    cnt = cnt+1
   end if
  end do
 end do
 write(*,*) cnt
end program main