program main
  implicit none
  integer :: n, i, j, d, res, sd
  integer, allocatable :: x(:, :)
  read (*, *) n, d
  allocate (x(n, d))
  do i = 1, n
    read (*, *) x(i, :)
  end do

  res = 0
  do i = 1, n
    do j = i + 1, n
      sd = sdist(x(i, :), x(j, :))
      if (is_squared(sd)) res = res + 1
    end do
  end do

  write (*, "(i0)") res

  contains

  pure integer function sdist(x1, x2)
    integer, intent(in) :: x1(d), x2(d)
    sdist = sum((x1 - x2) ** 2)
  end function sdist

  pure logical function is_squared(k)
    integer, intent(in) :: k
    is_squared = (k == nint(sqrt(dble(k))) ** 2)
  end function is_squared
end program main
