N = gets.to_i
arr = gets.split(" ").map(&:to_i)
sum1 = 0
sum2 = 0
sum3 = 0
index = 0
tmp = 0

roop = true

arr.each do |n|
    sum1 += n
end

N.times do
    if sum2 < sum1/2
        sum2 += arr[index]
    else
        if roop
            tmp = index - 1
            sum3 += arr[index]
            roop = false
        else
            sum3 += arr[index]
        end
    end
    index += 1
end

sum2 -= arr[tmp]
if sum2 == sum3
    puts arr[tmp]
elsif sum2 > sum3
    puts (sum2 - (sum3+arr[tmp])).abs
else
    puts (sum3 - (sum2+arr[tmp])).abs
end
    