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