program main 
 implicit  none
 integer,allocatable :: x(:)
 integer :: p,i,n,w(1:3)
  read *, n
  allocate(x(n))
  read *, x(:)
  p=int(sum(x)/n)
  w(:)=0
 do i=1,n
  w(1)=w(1)+(x(i)-p)**2
  w(2)=w(2)+(x(i)-p-1)**2
  w(3)=w(3)+(x(i)-p+1)**2
 end do
 
 write(*,'(i0)') minval(w)
 
end program main