program main
  implicit none
  real i, j, N, D, d2, k,d1
  integer ans
  integer,allocatable :: x(:,:)

  read(*, *) N, D
  allocate(x(N,D))
  do i = 1,N
    read(*, *) (x(i,j), j = 1,D)
  end do
  ans = 0
  do i = 1,N-1
    do j = i+1,N
      d2 = 0
      do k = 1,D
        d2 = d2 + (x(i,k)-x(j,k))**2
      end do
      d1 = floor(sqrt(d2))
      if (d1**2 == d2) then
        ans = ans+1
      endif
    end do
  end do


  write(*,*) ans
end program main
