program DDCC2020B
    implicit none
    integer(8)::N,i
    integer(8)::sum_half=0
    integer(8)::sum_A
    integer(8),allocatable,dimension(:)::A,A_diff

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

    sum_A=sum(A)

    do i=1,N
       sum_half=sum_half+A(i)
       A_diff(i)=abs(2*sum_half-sum_A)
    end do
    
    print'(i0)',minval(A_diff)

end program DDCC2020B