program main
  implicit none
  integer(8) :: n, i, to, res, mi
  integer(8), allocatable :: a(:)
  read(*, *) n
  allocate(a(n))
  read(*, *) (a(i), i = 1, n)

  mi = huge(0_8)
  do to = -100, 100
    res = 0
    do i = 1, n
      res = res + (a(i) - to) ** 2
    end do
    mi = min(mi, res)
  end do

  write(*, "(i0)") mi

  deallocate(a)
  contains
end
