n = int(input())
w = list(map(int, input().split()))

a = [0]*(n+1)
j = 0

for i in range(n):
  a[0] += w[i]

for i in range(n+1):
  if a[i] > 0:
    a[i+1] = a[i]- 2*w[i]
  else:
    j = i
    break
    
p = -a[j]
q = a[j-1]
if p < q:
  print(p)
else:
  print(q)



 n = int(input()) n int(input()) int input() input w = list(map(int, input().split())) w list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split a = [0]*(n+1) a [0]*(n+1) [0] 0 n+1 n 1 j = 0 j 0 for i in range(n):
  a[0] += w[i] i range(n) range n a[0] += w[i] a[0] a 0 w[i] w i for i in range(n+1):
  if a[i] > 0:
    a[i+1] = a[i]- 2*w[i]
  else:
    j = i
    break
     i range(n+1) range n+1 n 1 if a[i] > 0:
    a[i+1] = a[i]- 2*w[i]
  else:
    j = i
    break
     a[i] > 0 a[i] a i 0 a[i+1] = a[i]- 2*w[i] a[i+1] a i+1 i 1 a[i]- 2*w[i] a[i] a i 2*w[i] 2 w[i] w i j = i j i break p = -a[j] p -a[j] a[j] a j q = a[j-1] q a[j-1] a j-1 j 1 if p < q:
  print(p)
else:
  print(q) p < q p q print(p) print p print(q) print q p = -a[j] -a[j] p a = [0]*(n+1) [0]*(n+1) a n = int(input()) int(input()) n q = a[j-1] a[j-1] q j = 0 0 j j = i i j w = list(map(int, input().split())) list(map(int, input().split())) w
n = int(input())
w = list(map(int, input().split()))

a = [0]*(n+1)
j = 0

for i in range(n):
  a[0] += w[i]

for i in range(n+1):
  if a[i] > 0:
    a[i+1] = a[i]- 2*w[i]
  else:
    j = i
    break
    
p = -a[j]
q = a[j-1]
if p < q:
  print(p)
else:
  print(q)




