program DISCO2020yB
integer(16)::N
integer(16),allocatable::A(:)
integer(16) sumA
integer(16) cost,subsum
read*,N
allocate(A(N))
read*,A
sumA=(sum(A))
cost=huge(cost)
subsum=0
do i=1,N
  subsum=subsum+A(i)
  cost=min(cost,abs(sumA-2*subsum))
end do
print"(i0)",cost
end