program kadai
implicit none
real(8),parameter  ::  EPS=10e-8
integer  ::  n,m
integer,allocatable  ::  x(:,:)
real(8)  ::  ans
integer  ::  a
integer  ::  number
integer  ::  i,j,k

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

do i=1,n
    read(*,*) x(i,:)
end do
number=0

do i=1,n-1
    do j=i+1,n
        ans=0
        do k=1,m
            ans=ans+(x(i,k)-x(j,k))**2
        end do
        a=sqrt(ans)
!write(*,*) ans,a,number
        if (abs(real(a*a,8)-ans)<EPS) then
            number=number+1
        end if
       ! write(*,*) ans,a,number
    end do
end do

write(*,*) number


stop

end program kadai
