program main
  implicit none

  integer :: n, y, ans1, ans2, i
  integer, allocatable :: a(:), a2(:)
  

  read(*,*) n

  allocate(a(n))
  allocate(a2(n))

  read(*,*) a

  do i = 1, n
     a2(i) = a(i) * a(i)
  end do

  
  y = sum(a) / n
  ans1 = n * y * y - 2 * sum(a) * y + sum(a2)

  y = sum(a) / n + 1
  ans2 = n * y * y - 2 * sum(a) * y + sum(a2)

  if (ans1 >= ans2) then
     write(*,*) ans2
  else
     write(*,*) ans1
  end if

end program main


  
