program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,ans,ma
    integer(int32), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    a = a-minval(a)
    ma = maxval(a)
    if (ma==0) then
        print'(i0)', 0
        stop
    end if
    
    ans = 1000000000
    do i=1, ma
        ans = min(ans,sum(a*a))
        a(:) = a(:) - 1
    end do

    print'(i0)', ans
end program name