program rally
    implicit none
    integer n, i
    integer :: ansgt = 0, anslt = 0, ans = 0, sum = 0
    integer :: avelt = 0, avegt = 0, ave = 0, amari = 0
    integer,allocatable :: x(:)
    read *, n
    allocate(x(n))
    read *, x(:n)
    do i = 1, n
        sum = sum + x(i)
    end do
    amari = mod(sum, n)
    if(amari == 0)then
        ave = sum / n
        do i = 1, n
            ans = ans + (x(i) - ave)**2
        end do
        print *, ans
    else
        ave = sum / n
        avegt = ave + 1
        avelt = ave
        do i = 1, n
            ansgt = ansgt + (x(i) - avegt)**2
            anslt = anslt + (x(i) - avelt)**2
        end do
        if(ansgt < anslt)then
            print *, ansgt
        else
            print *, anslt
        end if
    end if
end program