CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
sa=sum(a)
hantei=2*(10**9)+1
sx=0
for i in range(len(a)-1):
  sx+=a[i]
  if abs(sa-2*sx)<hantei:
    hantei=abs(sa-2*sx)
print(hantei)

# Optimized solution
n=int(eval(input()))
#a,b=map(int,input().split())
a=list(map(int,input().split()))
#n=int(input())
#s=input()

sa=sum(a)
ans=10**10+1
x=0
for i in range(0,n-1):
  x+=a[i]
  if abs(2*x-sa)<ans:
    ans=abs(2*x-sa)
print(ans)
# Original solution
def main():
    n = int(eval(input()))
    a = [int(x) for x in input().split()]
    for i in range(1, n):
        a[i] += a[i - 1]
    answer = float("inf")
    for i in range(n - 1):
        answer = min(answer, abs(a[-1] - 2 * a[i]))
    print(answer)


if __name__ == '__main__':
    main()



# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    for i in range(1, n):
        a[i] += a[i - 1]
    ans = float("inf")
    for i in range(n - 1):
        ans = min(ans, abs(a[-1] - 2 * a[i]))
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = abs(A[0] - sum(A[1:]))
for i in range(1, N-1):
  ans = min(abs(sum(A[:i]) - sum(A[i:])), ans)
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
X = sum(A)
xi = A[0]
ans = abs(X - 2 * A[N-1])
for i in range(1, N-1):
  xi += A[i]
  ans = min(abs(X - 2 * xi), ans)
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
s=sum(a)
mi=10**15
for i in range(1,len(a)):
  s1=sum(a[0:i])
  s2=s-s1
  #print(s1,s2)
  mi=min([mi,abs(s1-s2)])
print(mi)

# Optimized solution
import sys
n=int(eval(input()))
a=list(map(int,input().split()))
s=sum(a)
if(n==2):
  mi=abs(a[0]-a[1])
else:
  mi=10**15
  s1=a[0]
  for i in range(1,len(a)-1):
    s1+=a[i]
    s2=s-s1
    #print(s1,s2)
    mi=min([mi,abs(s1-s2)])
print(mi)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
ans = float("Inf")
for i in range(1,n):
    ans = min(ans,abs(sum(a[:i])-sum(a[i:])))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int,input().split()))
b = sum(a)
c = 0
ans = float("Inf")
for i in range(n-1):
    c += a[i]
    b -= a[i]
    ans = min(ans,abs(b-c))
print(ans)
# Original solution
n = int(eval(input()))

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

total = sum(a)
ans = float("inf")
for i in range(n-1):
  x = sum(a[:i+1])
  y = total - x
  if(abs(x-y) < ans):
    ans = abs(x-y)
    
print(ans)

# Optimized solution
n = int(eval(input()))

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

total = sum(a)
x = 0
ans = float("inf")
for i in range(n-1):
  x += a[i]
  y = total - x
  if(abs(x-y) < ans):
    ans = abs(x-y)
    
print(ans)
# Original solution
from itertools import accumulate

eval(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
c = [abs(y * 2 - b[-1]) for y in b][:-1]
print((min([abs(y * 2 - b[-1]) for y in b][:-1])))

# Optimized solution
from itertools import accumulate

eval(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
B = []
for i in range(1,N):
    a = sum(A[:i])
    b = sum(A[i:])
    B.append(abs(a-b))
print((min(B)))


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
sum_A = sum(A)
ans = 10**20
X = 0
for a in A[:-1]:
    X += a
    ans = min(ans,abs(sum_A-2*X))
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))

ans=[]
for i in range(1,n):
    x=sum(a[0:i])
    y=sum(a[i:])
    ans.append(abs(x-y))

print((min(ans)))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))

total=sum(a)

ans=[]
x=0
for i in range(n-1):
    x+=a[i]
    y=total-x
    ans.append(abs(x-y))

print((min(ans)))
# Original solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    from itertools import accumulate

    N = int(eval(input()))  # len(A)
    A = list(map(int, input().split()))

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans=10**18
    for i in range(1, N):
        snuke=B[i]
        araiguma=sum(A)-B[i]
        ans=min(ans,abs(snuke-araiguma))
    print(ans)
resolve()

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    from itertools import accumulate

    N = int(eval(input()))  # len(A)
    A = list(map(int, input().split()))

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    ans=10**18
    for i in range(1, N):
        snuke=B[i]
        araiguma=B[N]-B[i]
        ans=min(ans,abs(snuke-araiguma))
    print(ans)
resolve()
# Original solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

N = int(eval(input()))
a = [int(i) for i in input().split()]

sum_a = sum(a)

ans = 10**10
for i in range(1,N):
    x = sum(a[:i])
    ans = min(ans,abs(sum_a-2*x))

print(ans)


# Optimized solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

N = int(eval(input()))
a = [int(i) for i in input().split()]

sum_a = sum(a)

ans = 10**10
x = 0
for i in range(N-1):
    x += a[i]
    ans = min(ans,abs(sum_a-2*x))

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
s = []
for i in range(1, N):
    s.append(abs(sum(A[0:i]) - sum(A[i:])))
print((min(s)))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf')
snu = 0
ara = sum(A)
for a in A[0:-1]:
    snu += a
    ara -= a
    ans = min(ans, abs(snu - ara))
print(ans)
# Original solution
N = int(eval(input()))
lst_a = list(map(int, input().split()))
total = sum(lst_a)
ans = float("INF")


for i in range(N - 1):
    x = sum(lst_a[:i+1])
    y = total - x
    ans = min(ans, abs(x - y))


print(ans)

# Optimized solution
N = int(eval(input()))
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")


for i in range(N - 1):
    x += lst_a[i]
    y = total - x
    ans = min(ans, abs(x - y))


print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
cnt = n//2
ans=abs(sum(a[:cnt]) - sum(a[cnt:]))
for i in range(1,cnt):
    if ans > abs(sum(a[:cnt+i]) - sum(a[cnt+i:])):
        ans = abs(sum(a[:cnt+i]) - sum(a[cnt+i:]))
for i in range(1,cnt):
    if ans > abs(sum(a[:cnt-i]) - sum(a[cnt-i:])):
        ans = abs(sum(a[:cnt-i]) - sum(a[cnt-i:]))
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**100
x=sum(a)
b=0
for i in a[:-1]:
   b+=i
   x-=i
   ans=min(ans,abs(x-b))
print(ans)
# Original solution
N = int(eval(input()))
a = [int(x) for x in input().split()]
ans = 10**9*N
for i in range(1,N):
    front = a[:i]
    back = a[i:]
    ans = min(ans, abs(sum(front)-sum(back)))
print(ans)

# Optimized solution
N = int(eval(input()))
a = [int(x) for x in input().split()]
ans = 10**9*N
front = 0
back = sum(a)
for i in range(N-1):
    front += a[i]
    back -= a[i]
    ans = min(ans, abs(front-back))
print(ans)
# Original solution
# ABC067C - Splitting Pile
def main():
    n = int(eval(input()))
    lst = list(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# ABC067C - Splitting Pile
def main():
    n = int(eval(input()))
    lst = tuple(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
# ARC078C - Splitting Pile (ABC067C)
from itertools import accumulate


def main():
    n = int(eval(input()))
    lst = tuple(accumulate(list(map(int, input().rstrip().split()))))
    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# ARC078C - Splitting Pile (ABC067C)
from itertools import accumulate


def main():
    n = int(eval(input()))
    lst = tuple(accumulate(list(map(int, input().rstrip().split()))))
    total = lst[-1]
    ans = min(abs(total - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
def main():
  n = int(eval(input()))
  a = list(input_list())
  sa = sum(a)
  ans = 10**10
  r = 0
  for v in list(a)[:-1]:
    r += v
    ans = min(ans, abs(sa - (2*r)))
  print(ans)

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

# Optimized solution
import collections


def main():
    n = int(eval(input()))
    a = input_list()
    sum_a = sum(a)
    wa = []
    for i, v in enumerate(a):
        if i == 0:
            wa.append(v)
        else:
            wa.append(v+wa[i-1])
    ans = float('inf')
    for i in range(n-1):
        ans = min(ans, abs(sum_a-(wa[i]*2)))
    print(ans)


def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))

ans=n*10**9

b=[0]
for i in range(1,n+1):
    b.append(a[i-1]+b[i-1])

for i in range(n-1):
    t_ans=abs(b[i+1]-(b[-1]-b[i+1]))
    ans=min(ans,t_ans)

print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))

ans=n*10**9
t=sum(a)

s=0

for i in range(n-1):
#    s=sum(a[:i])
    s+=a[i]
    ans=min(ans,abs(t-2*s))
print(ans)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
    snk = sum(A[:i])
    arg = sum(A[i:])
    res.append(abs(snk-arg))
if N == 2:
    print((abs(A[0] - A[1])))
else:
    print((min(res)))

# Optimized solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
res = []
for i in range(N-1):
    deltas.append(deltas[-1] - 2*A[i])
    res.append(abs(deltas[-1]))
print((min(res)))
# Original solution
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 10000000000000

for i in range(1,n):
  x = abs(sum(li[:i])-sum(li[i:]))
  if x < ans:
    ans = x

print(ans)

# Optimized solution
n = int(eval(input()))
li = list(map(int,input().split()))
ans = 10000000000000
x = 0
y = sum(li)

for i in range(0,n-1):
    x += li[i]
    y -= li[i]
    z = abs(x-y)
    if z < ans:
        ans = z

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**10
cnt=0
for i in range(len(a)-1):
    cnt+=a[i]
    ans=min(ans,abs(cnt*2-sum(a)))
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**10
cnt=0
rest=sum(a)
for i in range(len(a)-1):
    cnt+=a[i]
    rest-=a[i]
    ans=min(ans,abs(rest-cnt))
print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

total = sum(A)
x = 0
ans = 10000000007

for i in range(N):
    x += A[i]
    if i+1<N : ans=min(ans,abs(total-2*x))

print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

X = sum(A)
x = 0
ans = 10000000000007

for i in range(N):
    x += A[i]
    if i+1<N : ans=min(ans,abs(2*x-X))

print(ans)
# Original solution
n = int(eval(input()))

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

sm = sum(li_a)
result = -1
for c in range(1, len(li_a)):
    x = sum(li_a[0:c])
    a = abs(sm - 2 * x)
    result = min(result, a) if result >= 0 else a

print(result)

# Optimized solution
n = int(eval(input()))

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

sm = sum(li_a)

li_ruiseki = list()

for a in li_a:
    if len(li_ruiseki) == 0:
        li_ruiseki.append(a)
    else:
        li_ruiseki.append(li_ruiseki[-1] + a)

result = -1
for x in li_ruiseki[:-1]:
    a = abs(sm - 2 * x)
    result = min(result, a) if result >= 0 else a

print(result)
# Original solution
N=int(eval(input()))
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*(N-1)

for i in range(N-1):
  number_sum[i]=abs(sum(number[:i+1])*2-SUM)

print((min(number_sum)))

# Optimized solution
N=int(eval(input()))
number=list(map(int,input().split()))
Sum=sum(number)
number_sum=[0]*N
number_sum[0]=number[0]
result=[0]*(N-1)
for i in range(1,N):
  number_sum[i]=number_sum[i-1]+number[i]
result[0]=abs(number_sum[0]*2-Sum)
for i in range(1,N-1):
  result[i]=abs(((number_sum[i])*2-Sum))

print((min(result)))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

s = sum(a)

ans = float('inf')
for i in range(n-1):
    x = sum(a[:i+1])
    ans = min(ans, abs(s-2*x))

print(ans)


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

s = sum(a)

ans = float('inf')
x = 0
for i in range(n-1):
    x += a[i]
    ans = min(ans, abs(s-2*x))

print(ans)
# Original solution
# input
N = int(eval(input()))
A = list(map(int, input().split()))

sum_A = sum(A)
ans = abs(2 * A[0] - sum_A)

for i in range(1, N - 1):
    temp = 0
    for j in range(i):
        temp += A[j]
    temp = abs(2 * temp - sum_A)
    if temp < ans:
        ans = temp

print(ans)



# Optimized solution
# input
N = int(eval(input()))
A = list(map(int, input().split()))

sum_A = sum(A)
temp = 2 * A[0] - sum_A
ans = abs(temp)

for i in range(1, N - 1):
    temp = temp + 2 * A[i]
    if abs(temp) < ans:
        ans = abs(temp)

print(ans)
# Original solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
dp = [0] * N
dp[0] = sum(a)
res = float("inf")
for i in range(N - 1):
  dp[i + 1] = dp[i] - a[i]
for i in range(1, N):
  res = min(abs(2 * dp[i] - dp[0]), res)
print(res)

# Optimized solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
res = float("inf")
for i in range(1, N):
  res = min(res, abs(cs[i] - (cs[-1] - cs[i])))
print(res)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
ans=[]
for i in range(n-1):
    x=sum(a[:i+1:])
    ans.append(abs(2*x-total))
print((min(ans)))


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
ans=[]
x=0
for i in range(n-1):
    x+=a[i]
    ans.append(abs(2*x-total))
print((min(ans)))
# Original solution
import bisect
ans = float('inf')
n = int(eval(input()))
a = list(map(int, input().split()))
for i in range(1, n):
    ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
c = [0] * (N + 1)
for i in range(N):
    c[i + 1] = c[i] + a[i]
ans = float('inf')
for n in c[1:-1]:
    ans = min(ans, abs(c[-1] - 2 * n))
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
for i in range(1,N):
    su = sum(a[:i])
    ar = deck - su
    ans = min(ans, abs(su-ar))
print(ans)

# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))
ans = 10**10
deck = sum(a)
su = 0
for i in range(0,N-1):
    su = su + a[i]
    ar = deck - su
    ans = min(ans, abs(su-ar))
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int,(input().split())))
X = sum(a)
A = X-a[0]*2
for i in range(N-1):
  B = X -sum(a[0:i+1])*2
  if abs(B) < abs(A):
    A = B
print((abs(A)))

         


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
total = sum(A)
snk = A[0]
ari = total - snk
ans = abs(snk - ari)
for i in range(1,N-1):
  snk += A[i]
  ari -= A[i]
  ans = min(ans,abs(snk - ari))

print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

s = sum(a)
t = 0
ans = float("inf")

for i in range(n-1):
  t += a[i]
  s -= a[i]
  ans = min(ans, abs(s-t))
print(ans)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

x = 0
y = sum(a)
ans = float("inf")
for i in range(n-1):
  x += a[i]
  y -= a[i]
  z  = abs(x-y)
  if z < ans: ans = z
print(ans)
# Original solution
N=int(eval(input()))
A=[int(i) for i in input().split()]
CS=[A[0]]
for i in range(1,N-1):
  CS.append(CS[-1]+A[i])
SUM=sum(A)
ans=10**20
for s in CS:
  ans=min(ans,abs(SUM-s-s))
print(ans)

# Optimized solution
#C
N=int(eval(input()))
A=[int(i) for i in input().split()]

CS=[A[0]]
for i in range(1,N-1):
    CS.append(CS[-1]+A[i])

ans=10**19
SUM=sum(A)
for s in CS:
    ans=min(ans,abs(SUM-s-s))
print(ans)
# Original solution
N = int(eval(input()))
A = [int(s) for s in input().split()]

def main():
    ans = float('inf')
    for i in range(N - 1):
        A[i] *= -1
        ans = min(ans, abs(sum(A)))
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
N = int(eval(input()))
A = [int(s) for s in input().split()]

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), i))    
    abs_list.sort()
    idx = abs_list[0][1]

    left = sum(A[:idx + 1])
    right = sum(A[idx + 1:])
    print((abs(left - right)))

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(eval(input()))
    a = list(map(int, input().split()))

    # See:
    # https://atcoder.jp/img/arc078/editorial.pdf
    total_a = sum(a)
    diff = float('inf')

    for i in range(1, n):
        diff = min(diff, abs(total_a - 2 * sum(a[:i])))

    print(diff)


# Optimized solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from itertools import accumulate

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

    # See:
    # https://atcoder.jp/img/arc078/editorial.pdf
    # total_a = sum(a)
    summed_a = [0] + list(accumulate(a))
    total_a = sum(a)
    diff = float('inf')

    for i in range(1, n):
        diff = min(diff, abs(total_a - 2 * summed_a[i]))

    print(diff)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
ans = []
for i in range(1, n):
    ans.append(abs(sum(a[0:i]) - sum(a[i:n])))
print((min(ans)))

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
m = sum(a[:1])
n = sum(a[1:])
ans = [abs(m-n)]
for i in range(1, N-1):
    m += a[i]
    n -= a[i]
    ans.append(abs(m-n))
print((min(ans)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
tmp = 0
diffs = []
for i in range(N - 1):
    tmp += A[i]
    diffs.append(abs(sum(A) - tmp - tmp))
print((min(diffs)))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
tmp = 0
ans = 10 ** 10
Asum = sum(A)
for i in range(N - 1):
    tmp += A[i]
    a = abs((Asum - tmp) - tmp)
    if ans > a:
        ans = a
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
ans=10**100
for i in range(1,n):
  x=a[:i]
  y=a[i:]
  ans=min(ans,abs(sum(x)-sum(y)))
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
x=a[0]
y=sum(a[1:])
ans=abs(x-y)
for i in range(1,n-1):
  x+=a[i]
  y-=a[i]
  ans=min(ans,abs(x-y))
print(ans)
# Original solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]

mixi = abs(s[0] - (s[n-1] - s[0]))
for i in range(1, n-1):    # 全部取るのはダメ
    x, y = s[i], s[n-1] - s[i]
    mixi = min(mixi, abs(x - y))

print(mixi)

# Optimized solution
import sys
input = sys.stdin.readline

n = int(eval(input()))
a = [int(a) for a in input().split()]
s = [None] * n; s[0] = a[0]
for i in range(n-1): s[i+1] = s[i] + a[i+1]

mixi = abs(s[0] - (s[n-1] - s[0]))
for i in range(1, n-1): mixi = min(mixi, abs(s[i] - (s[n-1] - s[i])))   # 全部取るのはダメ

print(mixi)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf')
for i in range(1, N):
    x = sum(A[:i])
    y = sum(A[i:])
    d = abs(x-y)
    ans = min(ans, d)

print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)

for i in range(1, N-1):
    x += A[i]
    y = s - x
    d = abs(x-y)
    ans = min(ans, d)

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf')
s = sum(A)
x = A[0]
y = s - x
d = abs(x-y)
ans = min(ans, d)

for i in range(1, N-1):
    x += A[i]
    y = s - x
    d = abs(x-y)
    ans = min(ans, d)

print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))

ans = float('inf')
s = sum(A)

x = A[0]
ans = min(ans, abs(2*A[0]-s))

for i in range(1, N-1):
    x += A[i]
    ans = min(ans, abs(2*x-s))

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r.append(acu_r[-1] + A[i])
#print(acu)
#print(acu_r)
ans = float("inf")
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[N - (i + 2)]))
print(ans)



# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
ans = float("inf")
S = sum(A)
acu = []
acu.append(A[0])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-1):
  ans = min(ans,abs((S - acu[i]) - acu[i]))
print(ans)
# Original solution
# -*- coding:utf-8 -*-

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

SUM_CARD = sum(a)

i=1

diff_sum = 0
sunuke = sum(a[0:i])
diff_sum = abs(sunuke*2-SUM_CARD)
i+=1

while(i<N):
    sunuke = sum(a[0:i])
    diff_sum_new = abs(sunuke*2-SUM_CARD)
    if diff_sum_new<diff_sum:
        diff_sum = diff_sum_new
    i += 1

print(diff_sum)


# Optimized solution
# -*- coding:utf-8 -*-

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

SUM_CARD = sum(a)
i=0

sum_before = a[i]
diff_sum = abs(sum_before*2-SUM_CARD)
i+=1

while(i<N-1):
    sum_before = sum_before + a[i]
    diff_sum_new = abs(sum_before*2-SUM_CARD)
    if diff_sum_new<diff_sum:
        diff_sum = diff_sum_new
    i += 1

print(diff_sum)
# Original solution
N = int(eval(input()))
cards = list(map(int, input().split()))
x, y = 0, 0
ans = float("inf")
for i in range(1, N):
    x = sum(cards[:i])
    y = sum(cards[i:])
    if(abs(x-y) < ans):
        ans = abs(x-y)
print(ans)


# Optimized solution
N = int(eval(input()))
cards = list(map(int, input().split()))
ans = float("inf")
y = sum(cards)
x = 0
L = []

for card in cards:
    x += card
    y -= card
    L.append(abs(x-y))
    
del L[N-1]

print((min(L)))
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
if N == 2:
    print((abs(A[0] - A[1])))
    exit()

ans = []
for i in range(1, N-1):
    cards1 = A[:i]
    cards2 = A[i:]
    ans.append(abs(sum(cards1) - sum(cards2)))
print((min(ans)))


# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
ans = float('inf')
X = sum(A)
partial_sum = 0
for i in range(N-1):
    partial_sum += A[i]
    ans = min(ans, abs(X - 2 * partial_sum))
print(ans)
# Original solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
mn_list = []
for i in range(1,n):
    sunuke = sum(a[:i])
    araiguma = sum(a[i:])
    mn_list.append(abs(sunuke-araiguma))
print((min(mn_list)))

# Optimized solution
n = int(eval(input()))
a = [int(i) for i in input().split()]
mn_list = []
sunuke = a[0]
araiguma = sum(a[1:])
res = abs(sunuke-araiguma)
for i in range(1,n-1):
    sunuke += a[i]
    araiguma -= a[i]
    res = min(res,abs(sunuke-araiguma))
print(res)