program main
  implicit none
  integer :: n, i, p, a, b, sumx,sumx2
  integer, allocatable ::x(:)

  read *, n
  allocate( x(n) )
  read *, x

  sumx = 0
  sumx2 = 0
  do i = 1, n
    sumx = sumx + x(i)
    sumx2 = sumx2 + x(i)**2
  end do
  if ( mod(sumx,n) == 0 ) then
    p = sumx/n
    a = n*p**2 - 2*p*sumx + sumx2
    print *, a
  else
    p = sumx/n
    a = n*p**2 - 2*p*sumx + sumx2
    p = sumx/n+1
    b = n*p**2 - 2*p*sumx + sumx2
    if ( a>b ) then
      print *, b
    else
      print *, a
    end if
  end if

end program main
