import sys

input = sys.stdin.readline

import numpy as np

 

N=int(eval(input()))

A = np.array([int(x) for x in input().split()])

if N==2:

  print((abs(A[0]-A[1])))

else:

  B = np.concatenate([[0],A.cumsum()])

  H = np.searchsorted(B,sum(A)//2)

  result=float('inf')

  for i in range(min(5,len(A)//2)):

    result=min(result,abs(sum(A[:H+i])-sum(A[H+i:])),abs(sum(A[:H-i])-sum(A[H-i:])))



  print(result) 
import sys

input = sys.stdin.readline

import numpy as np

 

N=int(eval(input()))

A = np.array([int(x) for x in input().split()])

B = A.cumsum()



L=B

R=B[-1]-L



answer=np.abs(L-R).min()



print(answer)
import sys

input = sys.stdin.readline
import numpy as np

N = int(eval(input()))
A = np.array([int(x) for x in input().split()])
if N == 2:
    print((abs(A[0] - A[1])))
else:
    B = np.concatenate([[0], A.cumsum()])
    H = np.searchsorted(B, sum(A) // 2)
    result = float("inf")
    for i in range(min(5, len(A) // 2)):
        result = min(
            result,
            abs(sum(A[: H + i]) - sum(A[H + i :])),
            abs(sum(A[: H - i]) - sum(A[H - i :])),
        )
    print(result)

import sys

input = sys.stdin.readline
import numpy as np

N = int(eval(input()))
A = np.array([int(x) for x in input().split()])
B = A.cumsum()
L = B
R = B[-1] - L
answer = np.abs(L - R).min()
print(answer)

-if N == 2: -    print((abs(A[0] - A[1]))) -else: -    B = np.concatenate([[0], A.cumsum()]) -    H = np.searchsorted(B, sum(A) // 2) -    result = float("inf") -    for i in range(min(5, len(A) // 2)): -        result = min( -            result, -            abs(sum(A[: H + i]) - sum(A[H + i :])), -            abs(sum(A[: H - i]) - sum(A[H - i :])), -        ) -    print(result) +B = A.cumsum() +L = B +R = B[-1] - L +answer = np.abs(L - R).min() +print(answer)