from itertools import accumulate, count



eval(input())

a = [0] + list(accumulate(list(map(int, input().split()))))

i = next(i for i in count() if 2 * a[i] > a[-1])

print((min(2 * a[i] - a[-1], a[-1] - 2 * a[i - 1])))

from itertools import accumulate, count

from bisect import bisect_right



eval(input())

a = [0] + list(accumulate(list(map(int, input().split()))))

i = bisect_right(a, a[-1] // 2)

print((min(2 * a[i] - a[-1], a[-1] - 2 * a[i - 1])))

from itertools import accumulate, count

eval(input())
a = [0] + list(accumulate(list(map(int, input().split()))))
i = next(i for i in count() if 2 * a[i] > a[-1])
print((min(2 * a[i] - a[-1], a[-1] - 2 * a[i - 1])))

from itertools import accumulate, count
from bisect import bisect_right

eval(input())
a = [0] + list(accumulate(list(map(int, input().split()))))
i = bisect_right(a, a[-1] // 2)
print((min(2 * a[i] - a[-1], a[-1] - 2 * a[i - 1])))

+from bisect import bisect_right -i = next(i for i in count() if 2 * a[i] > a[-1]) +i = bisect_right(a, a[-1] // 2)