program main
  implicit none

  integer :: n, d, a(10,10), i, j, c, k, di

  read(*,*)n,d
  do i = 1, n
    read(*,*)(a(i,j),j = 1, d)
  end do
  c = 0
  do i = 1, n - 1
    do j = i + 1, n
      di = 0
      do k = 1, d
        di = di + (a(i,k) - a(j,k))**2
      end do
      if ((di - nint(sqrt(real(di)))**2) == 0) then
        c = c + 1
      end if
    end do
  end do

  write(*,*)c

end program main