program ARC059C
    implicit none
    integer(8)::N,i,j
    integer(8),allocatable,dimension(:)::A
    integer(8)::result,result_min

    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)

    do i=minval(A),maxval(A)
        result=0
        do j=1,N
            result=result+(i-A(j))**2
        end do

        if(i==minval(A))then
            result_min=result
        else if(result<result_min)then
            result_min=result
        end if
    end do

    print'(i0)',result_min
    
end program ARC059C