n=gets.to_i
array=gets.split.map(&:to_i)
sum=array.inject(:+)

sumnow=0
sumleft=0
sumright=0
array.map{|value|
    sumnow+=value
    if sumnow*2>=sum
        sumleft=sumnow-value
        sumright=sumnow
        break
    end
}


puts [2*sumright-sum,sum-2*sumleft].min
