program sample
	implicit none
    integer(8) :: N,i,count,average,sum1
    integer(8),allocatable :: x(:),a(:),b(:)
    real(8) :: count2,average2
    
    read(*,*) N
    
    allocate(x(N))
    allocate(b(N))
    
    
    read(*,*) x
    
    !write(*,*) x
    
    count =0
    count2=0
    do i=1,N
    	b(i) = x(i)-x(1)
        count = count +x(i)
        count2= count2 +real(x(i))
    end do
    
    average = count / N
    average2 = count2 /N
    
    sum1= 0
    if (maxval(b) ==minval(b)) then
    	write(*,*) 0
    else if (abs(average2-average) >= abs(average2-average-1) ) then
    	do i=1,N
        	sum1= sum1 + (x(i)-average-1)**2
        end do
        write(*,*) sum1
    else
    	do i=1,N
        	sum1 = sum1 + (x(i)-average) **2
    	end do
    	write(*,*) sum1
    end if
    
	deallocate(x)
    stop
end program sample