program prob3
    implicit none
    integer::n, i
    integer(16),allocatable::a(:)
    integer(16)::s, c, cnt, re, c2, re2
    read(*,*) n
    allocate(a(n))
    read(*,*) a
    s = sum(a)
    c = 0
    c2 = 0
    cnt = 0

    do i = 1, n
        c = c+a(i)
        c2 = c2+a(i)
        cnt = cnt + 1
        if(c >= s/2)then
            c2 = c-a(i)
            exit
        end if
        if(i == n-1) then
        	exit
        end if
    end do

    re = s - c
    re2 = s - c2

    write(*,*) min(abs(c-re),abs(c2-re2))

    stop
end program