import numpy as np



n = int(eval(input()))

a = list(map(int, input().split()))



cum = np.cumsum(a)

mid = cum[-1]/2

diff = 10**10

for each in cum:

  diff = min(diff, abs(mid-each))

  

print((int(diff/0.5)))
n = int(eval(input()))

a = list(map(int, input().split()))



mid = sum(a)/2

cum = 0

diff = 10**10

for each in a:

  cum += each

  diff = min(diff, abs(mid-cum))

  

print((int(diff/0.5)))
import numpy as np

n = int(eval(input()))
a = list(map(int, input().split()))
cum = np.cumsum(a)
mid = cum[-1] / 2
diff = 10**10
for each in cum:
    diff = min(diff, abs(mid - each))
print((int(diff / 0.5)))

n = int(eval(input()))
a = list(map(int, input().split()))
mid = sum(a) / 2
cum = 0
diff = 10**10
for each in a:
    cum += each
    diff = min(diff, abs(mid - cum))
print((int(diff / 0.5)))

-import numpy as np - -cum = np.cumsum(a) -mid = cum[-1] / 2 +mid = sum(a) / 2 +cum = 0 -for each in cum: -    diff = min(diff, abs(mid - each)) +for each in a: +    cum += each +    diff = min(diff, abs(mid - cum))