Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - -10^{9} \leq a_i \leq 10^{9}
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N}

-----Output-----
Print the answer.

-----Sample Input-----
6
1 2 3 4 5 6

-----Sample Output-----
1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

Difficulty: EASY

Solutions:
n = int(input())
a = list(map(int, input().split()))
lsum = a[0]
rsum = sum(a[1:])
ans = abs(lsum - rsum)
for i in range(1, n - 1):
	lsum += a[i]
	rsum -= a[i]
	res = abs(lsum - rsum)
	if res < ans:
		ans = res
print(ans)


import os
import sys
from itertools import accumulate

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A_ac = list(accumulate(A))
	ans = A_ac[-1]
	for (i, ac) in enumerate(A_ac):
		if i == 0:
			ans = abs(2 * ac - A_ac[-1])
		if i == N - 1:
			break
		if abs(2 * ac - A_ac[-1]) < ans:
			ans = abs(2 * ac - A_ac[-1])
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
x = sum(A)
y = 0
z = []
for n in range(N - 1):
	y += A[n]
	z.append(abs(x - 2 * y))
print(min(z))


N = int(input())
L = list(map(int, input().split()))
s = sum(L)
r = N * 10 ** 9
p = 0
for i in range(N - 1):
	p += L[i]
	r = min(r, abs(2 * p - s))
print(r)


n = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
INF = 10 ** 18
ans = INF
X = 0
for a in A[:-1]:
	X += a
	ans = min(ans, abs(2 * X - sum_A))
print(ans)


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '6\n1 2 3 4 5 6'
		output = '1'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '2\n10 -10'
		output = '20'
		self.assertIO(input, output)

def resolve():
	N = int(input())
	A = list(map(int, input().split()))
	ans = float('inf')
	S = sum(A)
	T = []
	T.append(A[0])
	for i in range(1, N):
		T.append(T[i - 1] + A[i])
	if N == 2:
		ans = abs(A[0] - A[1])
	else:
		for i in range(1, N - 1):
			ans = min(ans, abs(S - 2 * T[i]))
	print(ans)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
s = a[0] - sum(a[1:])
d = abs(s)
for i in range(1, n - 1):
	s += 2 * a[i]
	d = min(d, abs(s))
print(d)


N = int(input())
A = list(map(int, input().split()))
X = sum(A)
x = 0
result = []
for i in range(N - 1):
	x += A[i]
	result.append(abs(X - 2 * x))
print(min(result))


n = int(input())
a = list(map(int, input().split()))
s1 = sum(a)
s2 = 0
ans = 10 ** 18
for i in range(n - 1):
	s1 -= a[i]
	s2 += a[i]
	ans = min(ans, abs(s1 - s2))
print(ans)


N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans = 100 ** 100
x = 0
for i in range(N - 1):
	x += a[i]
	ans = min(ans, abs(A - 2 * x))
print(ans)


n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(n - 1):
	x += a[i]
	ln.append(abs(z - 2 * x))
print(min(ln))


(n, *A) = map(int, open(0).read().split())
(x, y) = (A[0], 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)


N = int(input())
A = list(map(int, input().split()))
T = [0] * N
S = sum(A)
for i in range(1, N):
	T[i] = T[i - 1] + A[i - 1]
print(min((abs(S - 2 * T[i]) for i in range(1, N))))


import numpy as np
N = int(input())
a = list(map(int, input().split()))
a = np.array(a)
cum = np.cumsum(a)[:-1]
rcum = np.cumsum(a[::-1])[:-1]
ans = abs(cum - rcum[::-1])
print(np.min(ans))


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = float('inf')
c = 0
for ai in a[:-1]:
	c += ai
	ans = min(ans, abs(s - c - c))
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
s1 = 0
ans = 10 ** 15
for i in range(n - 1):
	s1 += a[i]
	ans = min(ans, abs(s1 - (s - s1)))
print(ans)


from itertools import *
(*a, s) = list(accumulate(map(int, open(0).read().split()[1:])))
print(min((abs(s - x * 2) for x in a)))


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
(temp, ans) = (0, float('inf'))
for v in a[:-1]:
	temp += v
	s -= v
	ans = min(ans, abs(temp - s))
print(ans)


n = int(input())
arr = list(map(int, input().split()))
sum1 = 0
sum2 = sum(arr)
min_ = 1 << 60
for i in range(n - 1):
	sum1 += arr[i]
	sum2 -= arr[i]
	min_ = min(min_, abs(sum1 - sum2))
print(min_)


n = int(input())
a = list(map(int, input().split()))
ans = float('inf')
x = 0
b = sum(a)
for i in range(n):
	x += a[i]
	if i + 1 < n:
		ans = min(ans, abs(b - 2 * x))
print(ans)


def main():
	n = int(input())
	a_lst = list(map(int, input().split()))
	x = a_lst[0]
	y = sum(a_lst) - x
	minimum = abs(x - y)
	for i in range(1, n - 1):
		a = a_lst[i]
		x += a
		y -= a
		minimum = min(minimum, abs(x - y))
	print(minimum)

def __starting_point():
	main()
__starting_point()


INF = pow(10, 10)

def solve(n, a):
	res = INF
	x = 0
	y = sum(a)
	for i in range(n - 1):
		x += a[i]
		y -= a[i]
		res = min(res, abs(x - y))
	return res

def main():
	N = int(input())
	a = list(map(int, input().split()))
	print(solve(N, a))
	return

def __starting_point():
	main()
__starting_point()


from itertools import accumulate as ac
N = int(input())
A = list(ac(map(int, input().split())))
S = A.pop()
print(min((abs(S - 2 * a) for a in A)))


n = int(input())
a = list(map(int, input().split()))
ans = 10 ** 50
x = 0
X = sum(a)
for i in range(n - 1):
	x += a[i]
	f = abs(X - 2 * x)
	ans = min(ans, f)
print(ans)


n = int(input())
a = list(map(int, input().split()))
t = sum(a)
m = 10 ** 9
flag = 0
for i in range(len(a) - 1):
	t -= 2 * a[i]
	if i == 0:
		m = abs(t)
	else:
		m = min(abs(t), m)
print(m)


n = int(input())
a = list(map(int, input().split()))
sa = sum(a)
x = a[0]
m = abs(sa - 2 * x)
for i in range(1, n - 1):
	x += a[i]
	m = min(m, abs(sa - 2 * x))
print(m)


n = int(input())
a = list(map(int, input().split()))
p = sum(a)
snuke = 0
ans = 10 ** 10
for i in range(n - 1):
	snuke += a[i]
	ans = min(ans, abs(p - 2 * snuke))
print(ans)


from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a_acc = list(accumulate(a))
print(min((abs(a_acc[-1] - 2 * x) for x in a_acc[:-1])))


N = int(input())
A = list(map(int, input().split()))
sunuke = [0] * N
guma = [0] * N
for i in range(N - 1):
	if i == 0:
		sunuke[i] += A[i]
		continue
	sunuke[i] += sunuke[i - 1] + A[i]
for j in range(N - 1, 0, -1):
	if j == N - 1:
		guma[j] += A[j]
		continue
	guma[j] += guma[j + 1] + A[j]
ans = float('inf')
for k in range(N - 1):
	ans = min(ans, abs(sunuke[k] - guma[k + 1]))
print(ans)


from itertools import accumulate
N = int(input())
A = list(accumulate(map(int, input().split())))
print(min((abs(A[N - 1] - 2 * A[i]) for i in range(N - 1))))


n = int(input())
a = [int(i) for i in input().split()]
x = 0
k = sum(a)
m = 2 * 10 ** 9
for i in range(n - 1):
	x += a[i]
	if m > abs(2 * x - k):
		m = abs(2 * x - k)
print(m)


N = int(input())
a = [int(x) for x in input().split()]
l = 0
r = sum(a)
d = []
for i in range(N - 1):
	l += a[i]
	r -= a[i]
	d.append(abs(l - r))
print(min(d))


n = int(input())
a = list(map(int, input().split()))
tot = sum(a) - a[0]
s = a[0]
m = abs(s - tot)
for x in a[1:n - 1]:
	tot -= x
	s += x
	m = min(m, abs(s - tot))
print(m)


N = int(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)


N = int(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)


N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
ans = 10 ** 11
x = 0
for i in range(N - 1):
	x += a[i]
	diff = abs(sum_a - 2 * x)
	if diff < ans:
		ans = diff
print(ans)


N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(s - 2 * a[0])
for i in range(1, N - 1):
	data.append(a[i] + data[i - 1])
for i in range(0, N - 1):
	if abs(s - 2 * data[i]) < m:
		m = abs(s - 2 * data[i])
print(m)


n = int(input())
a = list(map(int, input().split()))
y = sum(a)
x = 0
mn = 10 ** 18
for i in range(n - 1):
	x += a[i]
	y -= a[i]
	mn = min(mn, abs(x - y))
print(mn)


n = int(input())
a = list(map(int, input().split()))
su = a[0]
ar = sum(a[1:])
p = abs(su - ar)
for i in a[1:-1]:
	su += i
	ar -= i
	p = min(abs(su - ar), p)
print(p)


n = int(input())
a = list(map(int, input().split()))
ans = n * 10 ** 9
t = sum(a)
s = 0
for i in range(n - 1):
	s += a[i]
	ans = min(ans, abs(t - 2 * s))
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = 0
sn = sum(a)
ans = 1e+20
for i in range(n - 1):
	s += a[i]
	ans = min(ans, abs(sn - 2 * s))
print(ans)


N = int(input())
A = [int(i) for i in input().split()]
su = sum(A)
x = 0
mi = 1000000000000000.0
for a in A[:-1]:
	x += a
	mi = min(mi, abs(su - 2 * x))
print(mi)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
now = 0
ans = 10 ** 14
for i in a[:n - 1]:
	now += i
	ans = min(abs(2 * now - s), ans)
print(ans)


N = int(input())
a = list(map(int, input().split()))
t = sum(a)
x = t
ans = 10 ** 10
for ai in a[:-1]:
	x -= 2 * ai
	if ans > abs(x):
		ans = abs(x)
print(ans)


n = int(input())
A = list(map(int, input().split()))
X = sum(A)
ans = 10 ** 100
x = 0
for i in range(n - 1):
	x += A[i]
	ans = min(ans, abs(X - 2 * x))
print(ans)


N = int(input())
A = [0] + list(map(int, input().split()))
for i in range(1, N + 1):
	A[i] = A[i] + A[i - 1]
ans = float('inf')
for i in range(1, N):
	ans = min(ans, abs(A[N] - 2 * A[i]))
print(ans)


a = int(input())
b = [int(s) for s in input().split()]
su = sum(b) - b[a - 1]
ar = b[a - 1]
ans = abs(su - ar)
for i in range(2, a - 1):
	su = su - b[a - i]
	ar = ar + b[a - i]
	tmp = abs(su - ar)
	if tmp < ans:
		ans = tmp
	tmp = 0
print(ans)


from itertools import accumulate
input()
A = list(accumulate([int(i) for i in input().split()]))
ans = 99 ** 9
for a in A[:-1]:
	ans = min(ans, abs(A[-1] - a - a))
print(ans)


n = int(input())
A = list(map(int, input().split()))
sumA = sum(A)
T = [0] * n
for i in range(1, n):
	T[i] = T[i - 1] + A[i - 1]
print(min((abs(sumA - 2 * T[i]) for i in range(1, n))))


n = int(input())
A = list(map(int, input().split()))
r = sum(A) - A[0]
l = A[0]
ans = abs(r - l)
for i in range(1, len(A) - 1):
	r -= A[i]
	l += A[i]
	ans = min(ans, abs(l - r))
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
ans = float('inf')
res = 0
for i in range(n - 1):
	res += a[i]
	ans = min(ans, abs(s - 2 * res))
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
l = float('inf')
for i in range(n - 1):
	x += a[i]
	y = y - a[i]
	l = min(l, abs(x - y))
print(l)


n = int(input())
a = list(map(int, input().split()))
import math
sunuke = 0
kuma = sum(a)
memo = abs(2 * a[0] - sum(a))
ans = abs(2 * a[0] - sum(a))
for i in range(n):
	sunuke += a[i]
	kuma -= a[i]
	if abs(sunuke - kuma) > memo:
		ans = memo
	else:
		memo = abs(sunuke - kuma)
print(ans)


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


n = int(input())
A = list(map(int, input().split()))
for i in range(n - 1):
	A[i + 1] += A[i]
S = A[-1]
A = [abs(2 * a - S) for a in A[:-1]]
print(min(A))


N = int(input())
A = [int(a) for a in input().split(' ')]
sA = []
for i in range(len(A)):
	if i == 0:
		sA.append(A[0])
	else:
		sA.append(sA[i - 1] + A[i])
s = sum(A)
dA = [abs(2 * sA[j] - s) for j in range(len(sA) - 1)]
print(min(dA))


N = int(input())
a = list(map(int, input().split()))
s = sum(a)
su = a[0]
ar = s - su
ans = abs(su - ar)
for i in range(1, N - 1):
	su += a[i]
	ar = s - su
	if ans > abs(su - ar):
		ans = abs(su - ar)
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [a[0]]
for i in range(1, n):
	b.append(b[-1] + a[i])
s = sum(a)
ans = 10 ** 20
for i in range(n - 1):
	ans = min(ans, abs(s - 2 * b[i]))
print(ans)


n = int(input())
l = list(map(int, input().split()))
su = l[0]
s = sum(l)
ans = abs(s - 2 * su)
for i in l[1:-1]:
	su += i
	ans = min(ans, abs(s - 2 * su))
print(ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
from collections import Counter, deque

def i_input():
	return int(input())

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

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]
import string

def main():
	n = i_input()
	a = i_list()
	total = sum(a)
	ans = INF
	trial = 0
	for i in a[:-1]:
		trial += i
		left = total - trial
		ans = min(ans, abs(trial - left))
	print(ans)

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
s = 0
l = sum(A)
r = []
for a in A[:-1]:
	s += a
	k = abs(l - 2 * s)
	r.append(k)
r.sort()
print(r[0])


n = int(input())
A = list(map(int, input().split()))
s = sum(A)
c = 0
ans = float('inf')
for i in range(n - 1):
	c += A[i]
	ans = min(ans, abs(c - (s - c)))
print(ans)


N = int(input())
a = [int(i) for i in input().split()]
X = sum(a)
b = []
c = 0
for i in a[:-1]:
	c += i
	b.append(abs(X - 2 * c))
print(min(b))


N = int(input())
A = list(map(int, input().split()))
T = 0
S = sum(A)
ans = 10 ** 18
for a in A[:-1]:
	T += a
	S -= a
	ans = min(ans, abs(T - S))
print(ans)


n = int(input())
a = list(map(int, input().split()))
t = sum(a)
mi = abs(t - 2 * a[0])
k = a[0]
for i in range(1, n - 1):
	k = k + a[i]
	if abs(t - 2 * k) < mi:
		mi = abs(t - 2 * k)
print(mi)


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


N = int(input())
A = list(map(int, input().split()))
M = sum(A)
x0 = 0
D = abs(M - 2 * A[N - 1])
for i in range(N - 1):
	x0 += A[i]
	D = min(D, abs(M - 2 * x0))
print(D)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a_sum = sum(a)
	cnt = 0
	ans = float('inf')
	for i in range(n - 1):
		cnt += a[i]
		ans = min(ans, abs(a_sum - cnt * 2))
	else:
		print(ans)
main()


n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
s = 0
res = float('inf')
for v in a[:-1]:
	s += v
	res = min(res, abs(sum_a - 2 * s))
print(res)


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


n = int(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)


n = int(input())
a = list(map(int, input().split()))
r = sum(a)
l = 0
ans = float('INF')
for i in range(n - 1):
	l += a[i]
	r -= a[i]
	ans = min(ans, abs(l - r))
print(ans)


N = int(input())
a = [int(e) for e in input().split()]
x = 0
y = sum(a)
cand = []
for e in a[:N - 1]:
	x += e
	y -= e
	cand.append(abs(x - y))
print(min(cand))


n = int(input())
a = list(map(int, input().split()))
(s, t) = (sum(a), 0)
l = []
for i in a:
	t += i
	l += [abs(s - t * 2)]
print(min(l[:-1]))


n = int(input())
A = list(map(int, input().split()))
s = A[0]
s_ = sum(A[1:])
gap = abs(s - s_)
for i in range(1, n - 1):
	s += A[i]
	s_ -= A[i]
	if gap > abs(s - s_):
		gap = abs(s - s_)
print(gap)


n = int(input())
a = list(map(int, input().split()))
cumsum = [0 for _ in range(n)]
cumsum[0] = a[0]
for i in range(1, n):
	cumsum[i] = a[i] + cumsum[i - 1]
result = [0 for _ in range(n - 1)]
last = cumsum[-1]
for i in range(n - 1):
	result[i] = abs(last - 2 * cumsum[i])
print(min(result))


N = int(input())
a = list(map(int, input().split()))
sum = [0]
for i in range(0, N):
	sum.append(sum[-1] + a[i])
ans = abs(sum[N] - 2 * sum[1])
for i in range(1, N):
	ans = min(ans, abs(sum[N] - 2 * sum[i]))
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = [-sum(a)]
for i in range(1, n):
	l.append(l[i - 1] + a[i - 1] * 2)
l = l[1:]
for i in range(n - 1):
	l[i] = abs(l[i])
print(min(l))


n = int(input())
a = [0] + list(map(int, input().split()))
import itertools
a = list(itertools.accumulate(a))
ans = 1000000000000000.0
for i in range(1, n):
	ans = min(ans, abs(a[n] - 2 * a[i]))
print(ans)


N = int(input())
A = [int(a) for a in input().split()]
d = sum(A)
mi = 1 << 100
for i in range(N - 1):
	d -= 2 * A[i]
	mi = min(mi, abs(d))
print(mi)


N = int(input())
a = list(map(int, input().split()))
ans = float('inf')
snuke = 0
arai = sum(a)
for i in range(N - 1):
	snuke += a[i]
	arai -= a[i]
	ans = min(abs(snuke - arai), ans)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
x = a[0]
y = sum(a[1:])
m = abs(x - y)
i = 1
while i < n - 1:
	x += a[i]
	y -= a[i]
	m = min(abs(x - y), m)
	i += 1
print(m)


from itertools import accumulate
INF = float('inf')
N = int(input())
A = [int(x) for x in input().split()]
cumA = list(accumulate(A))
ans = INF
for i in range(N - 1):
	x = cumA[i]
	y = cumA[N - 1] - cumA[i]
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
a = list(map(int, input().split()))
nums = []
total = 0
for num in a:
	total += num
	nums.append(total)
minVal = 10 ** 9 * 2 + 1
for i in range(n - 1):
	sub = total - nums[i]
	minVal = min(abs(sub - nums[i]), minVal)
print(minVal)


n = int(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))


n = int(input())
c = list(map(int, input().split()))
s = sum(c)
l = []
x = 0
y = s
for i in c[:n - 1]:
	x += i
	y -= i
	l += [abs(x - y)]
print(min(l))


from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
(*B, su) = list(accumulate(A))
print(min((abs(su - 2 * b) for b in B)))


n = int(input())
l = [int(i) for i in input().split()]
s = sum(l)
mini = 10 ** 10
p = 0
for i in range(n - 1):
	p += l[i]
	mini = min(mini, abs(p - (s - p)))
print(mini)


N = int(input())
L = list(map(int, input().split()))
S = sum(L)
k = 0
ans = abs(2 * sum(L[0:1]) - S)
for i in range(0, N - 1):
	k += L[i]
	ans = min(ans, abs(2 * k - S))
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = [0]
for i in a:
	x.append(x[-1] + i)
ans = 10 ** 11
for i in x[1:-1]:
	ans = min(ans, abs(i * 2 - x[-1]))
print(ans)


(n, x, *a, b) = map(int, open(0).read().split())
y = sum(a) + b
z = abs(x - y)
for i in a:
	x += i
	y -= i
	z = min(z, abs(x - y))
print(z)


n = int(input())
A = [int(i) for i in input().split()]
x = sum(A)
y = 0
ans = 10 ** 16
for i in range(n - 1):
	x -= A[i]
	y += A[i]
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
A = list(map(int, input().split()))
sum_A = [0 for _ in range(n + 1)]
for i in range(1, n + 1):
	sum_A[i] = sum_A[i - 1] + A[i - 1]
ans = float('inf')
for i in range(1, n):
	ans = min(abs(sum_A[i] - (sum_A[-1] - sum_A[i])), ans)
print(ans)


from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
AA = list(accumulate([0] + A))
ans = 10 ** 20
for i in range(1, n):
	temp1 = AA[i]
	temp2 = AA[-1] - temp1
	delta = abs(temp1 - temp2)
	ans = min(delta, ans)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
s = [0] * (n + 2)
for i in range(n):
	s[i + 1] = s[i] + a[i]
res = 10 ** 10
for i in range(1, n):
	res = min(res, abs(s[i] - (s[n] - s[i])))
print(res)


N = int(input())
A = list(map(int, input().split()))
S = sum(A)
X = 0
D = float('inf')
for i in range(N):
	X += A[i]
	if i != N - 1:
		Y = S - X
		D = min(D, abs(X - Y))
print(D)


N = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
dif = []
s = 0
for i in range(N - 1):
	s += a[i]
	r = sum_a - s
	dif.append(abs(r - s))
print(min(dif))


import numpy as np
n = int(input())
al = list(map(int, input().split()))
bl = list(np.cumsum(al))
ans = 1001001001001
for i in range(n - 1):
	ans = min(ans, abs(bl[i] - (bl[-1] - bl[i])))
print(ans)


n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1):
	a[i + 1] += a[i]
m = a[-1]
ans = 10 ** 18
for i in range(n - 1):
	ans = min(ans, abs(m - 2 * a[i]))
print(ans)


n = int(input())
b = []
a = list(map(int, input().split()))
k = a[0]
s = sum(a)
for i in range(n - 1):
	b.append(abs(s - k * 2))
	k += a[i + 1]
print(min(b))


N = int(input())
A = list(map(int, input().split()))
P = A[0]
Q = sum(A[1:])
m = abs(P - Q)
for i in range(1, N - 1):
	P += A[i]
	Q -= A[i]
	m = min(m, abs(P - Q))
print(m)


n = int(input())
a = list(map(int, input().split()))
val = 0
l = []
s = sum(a)
hlf = s / 2
for i in range(n - 1):
	val += a[i]
	l.append(abs(hlf - val))
val = min(l)
print(int(val * 2))


n = int(input())
main = list(map(int, input().split()))
total = sum(main)
beg = 0
final = float('inf')
for i in range(len(main) - 1):
	beg += main[i]
	total -= main[i]
	final = min(final, abs(beg - total))
print(final)


n = int(input())
a = [int(i) for i in input().split()]
i = a[0]
j = sum(a) - i
ans = abs(i - j)
x = 1
while x + 1 != n:
	i += a[x]
	j -= a[x]
	ans = min(ans, abs(i - j))
	x += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
asum = [0] * (n + 1)
for i in range(n):
	asum[i + 1] = asum[i] + a[i]
ans = 10 ** 12
for i in range(1, n):
	snu = asum[i]
	arai = asum[-1] - asum[i]
	ans_ = abs(snu - arai)
	if ans > ans_:
		ans = ans_
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = sum(a)
c = 0
ans = float('Inf')
for i in range(n - 1):
	c += a[i]
	ans = min(ans, abs(b - 2 * c))
print(ans)


from itertools import accumulate as acc
input()
(*s, S) = list(acc(map(int, input().split())))
print(min((abs(S - 2 * x) for x in s)))


n = int(input())
A = list(map(int, input().split()))
sa = sum(A)
S = []
for i in range(0, n - 1):
	sa -= 2 * A[i]
	S.append(abs(sa))
print(min(S))


N = int(input())
A = list(map(int, input().split()))
S1 = A[0]
S2 = sum(A) - A[0]
B = [abs(S1 - S2)]
for i in range(N - 2):
	S1 += A[i + 1]
	S2 -= A[i + 1]
	B.append(abs(S1 - S2))
print(min(B))


N = int(input())
a = list(map(int, input().split()))
M = sum(a)
ans = float('inf')
snk = 0
for i in range(N - 1):
	snk += a[i]
	ans = min(ans, abs(M - 2 * snk))
print(ans)


n = int(input())
a = list(map(int, input().split()))
total = sum(a)
ans = []
for x in range(n - 1):
	total -= 2 * a[x]
	ans.append(abs(total))
print(min(ans))


n = int(input())
lst = list(map(int, input().split()))
ans = 0
x = sum(lst)
true = 10 ** 16
for i in range(n - 1):
	ans += lst[i]
	x -= lst[i]
	true = min(true, abs(ans - x))
print(true)


n = int(input())
A = list(map(int, input().split()))
(a, b) = (sum(A) - A[0], A[0])
cnt = abs(a - b)
for i in range(1, n - 1):
	b += A[i]
	a -= A[i]
	cnt = min(cnt, abs(a - b))
print(cnt)


N = int(input())
A = list(map(int, input().split()))
x = A[0]
y = sum(A[1:])
ans = abs(x - y)
for a in A[1:-1]:
	x += a
	y -= a
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
x = list(map(int, input().split()))
(a, b) = (x[0], sum(x) - x[0])
c = abs(a - b)
for i in range(1, n - 1):
	a += x[i]
	b -= x[i]
	c = min(c, abs(a - b))
print(c)


n = int(input())
al = list(map(int, input().split()))
sm = sum(al)
t = 0
ans = 10 ** 15
for i in range(n - 1):
	t += al[i]
	ans = min(ans, abs(sm - t * 2))
print(ans)


N = int(input())
a = list(map(int, input().split()))
x = 0
y = sum(a)
b = []
for i in range(N - 1):
	x += a[i]
	y -= a[i]
	b.append(abs(x - y))
print(min(b))


N = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
ans = float('inf')
x = a[0]
for i in range(1, N):
	ans = min(ans, abs(2 * x - sum_a))
	x += a[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = sum(a)
y = 0
ans = 10 ** 15
for i in range(n):
	y += a[i]
	if i + 1 < n:
		ans = min(ans, abs(x - 2 * y))
print(ans)


N = int(input())
a = list(map(int, input().split()))
s = sum(a)
l = 0
ans = 10 ** 10
for i in range(N - 1):
	l += a[i]
	ans = min(ans, abs(s - 2 * l))
print(ans)


N = int(input())
A = list(map(int, input().split()))
total = sum(A)
arai = 0
sunuke = 0
ans = float('inf')
for i in range(N - 1):
	sunuke += A[i]
	arai = total - sunuke
	ans = min(ans, abs(sunuke - arai))
print(ans)


n = int(input())
a = list(map(int, input().split()))
sa = sum(a)
cs = 0
arr = []
for i in range(n - 1):
	cs += a[i]
	ca = sa - cs
	arr.append(abs(cs - ca))
print(min(arr))


n = int(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[n - 1] - 2 * a[i]))
print(ans)


N = int(input())
a = list(map(int, input().split()))
ans = 10000000000000000000
c = 0
s = sum(a)
for i in range(N - 1):
	c += a[i]
	s -= a[i]
	if abs(c - s) < ans:
		ans = abs(c - s)
print(ans)


N = int(input())
a = list(map(int, input().split()))
A = [0] * (N + 1)
B = sum(a)
for i in range(N):
	A[i + 1] = A[i] + a[i]
t = 10 ** 15
for i in range(1, N):
	t = min(t, abs(2 * A[i] - B))
print(t)


N = int(input())
lsa = list(map(int, input().split()))
sunu = lsa[0]
ara = sum(lsa) - lsa[0]
ans = abs(ara - sunu)
for i in range(1, N - 1):
	sunu += lsa[i]
	ara -= lsa[i]
	ans = min(ans, abs(ara - sunu))
print(ans)


N = int(input())
(*A,) = map(int, input().split())
t = sum(A)
x = 0
ans = float('inf')
for i in range(N - 1):
	x += A[i]
	ans = min(ans, abs(2 * x - t))
print(ans)


import sys
from itertools import accumulate
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	n = int(input())
	A = list(map(int, input().split()))
	res = f_inf
	R = [0] + list(accumulate(A))
	for i in range(1, n):
		s = R[i] - R[0]
		a = R[-1] - R[i]
		diff = abs(s - a)
		res = min(res, diff)
	print(res)

def __starting_point():
	resolve()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] += a[i - 1]
ABS = 10 ** 15
for i in range(n - 1):
	ABS = min(abs(a[-1] - 2 * a[i]), ABS)
print(ABS)


n = int(input())
m = list(map(int, input().split()))
a = sum(m)
for i in range(1, n):
	m[i] += m[i - 1]
ans = 99999999999999
for i in m[:n - 1]:
	ans = min(ans, abs(a - i - i))
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
sunuke = 0
araiguma = sum(a)
min_sa = 100000000000000
for i in range(n - 1):
	sunuke += a[i]
	araiguma -= a[i]
	min_sa = min(min_sa, abs(araiguma - sunuke))
print(min_sa)


(_, *a) = map(int, open(0).read().split())
(s, t) = (sum(a), 0)
l = []
for i in a:
	t += i
	l += [abs(s - t * 2)]
print(min(l[:-1]))


N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = 1000000000000.0
work = 0
for i in range(N - 1):
	work += A[i]
	ans = min(ans, abs(S - 2 * work))
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
s = sum(a)
t = 0
for i in range(n - 1):
	b.append(t + a[i])
	t = b[i]
for i in range(n - 1):
	c.append(abs(2 * b[i] - s))
c.sort()
print(c[0])


N = int(input())
A = [int(x) for x in input().split()]
tmp = sum(A)
tmp -= 2 * A[0]
ans = abs(tmp)
for i in range(1, N - 1):
	tmp -= 2 * A[i]
	ans = min(abs(tmp), abs(ans))
print(ans)


n = int(input())
A = list(map(int, input().split()))
S = sum(A)
res = []
Sa = 0
for a in A[:-1]:
	Sa += a
	res.append(abs(2 * Sa - S))
print(min(res))


import itertools
n = int(input())
a = list(map(int, input().split()))
n_acc = itertools.accumulate(a)
sigma = sum(a)
ans = 10 ** 16
for (i, val) in enumerate(n_acc):
	if i == len(a) - 1:
		break
	rest = sigma - val
	ans = min(abs(val - rest), ans)
print(ans)


N = int(input())
a = list(map(int, input().split()))
(l, r) = (a.pop(0), sum(a))
ans = 10 ** 10
for i in a:
	ans = min(ans, abs(l - r))
	(l, r) = (l + i, r - i)
print(ans)


(n, *a) = map(int, open(0).read().split())
s = [0]
ans = 10 ** 20
for i in range(len(a)):
	s += [a[i] + s[-1]]
for i in range(1, len(s) - 1):
	ans = min(ans, abs(s[-1] - 2 * s[i]))
print(ans)


N = int(input())
a = list(map(int, input().split()))
sn = 0
ar = sum(a)
ans = 1e+17
for i in range(N - 1):
	sn += a[i]
	ar -= a[i]
	ans = min(ans, abs(sn - ar))
print(ans)


N = int(input())
a = list(map(int, input().split()))
s = sum(a)
l = a[0]
m = abs(s - l - l)
for i in range(1, N - 1):
	l += a[i]
	m = min(m, abs(s - l - l))
print(m)


N = int(input())
A = list(map(int, input().split()))
S = sum(A)
for i in range(1, N):
	A[i] += A[i - 1]
ans = 10 ** 10
for i in range(N - 1):
	ans = min(ans, abs(S - 2 * A[i]))
print(ans)


N = int(input())
a = list(map(int, input().split()))
x = a[0]
y = sum(a) - a[0]
out = abs(x - y)
for i in range(1, N - 1):
	x += a[i]
	y -= a[i]
	if abs(x - y) < out:
		out = abs(x - y)
print(out)


n = int(input())
a = list(map(int, input().split()))
l = []
s = sum(a)
cnt = 0
for i in range(n - 1):
	cnt += a[i]
	rem = s - cnt
	l.append(abs(cnt - rem))
print(min(l))


n = int(input())
a = list(map(int, input().split()))
s = sum(a)
x = 0
ans = abs(2 * a[0] - s)
snuke = a[0]
for i in range(1, n - 1):
	snuke += a[i]
	if abs(2 * snuke - s) < ans:
		ans = abs(2 * snuke - s)
print(ans)


n = int(input())
a = list(map(int, input().split()))
lis = []
b = sum(a)
cnt = 0
for i in range(n - 1):
	cnt += a[i]
	lis.append(abs(b - 2 * cnt))
print(min(lis))


n = int(input())
l = list(map(int, input().split()))
a = 10000000000
A = 0
B = sum(l)
for i in range(n - 1):
	A += l[i]
	B -= l[i]
	a = min(a, abs(A - B))
print(a)


n = int(input())
a = list(map(int, input().split()))
mi = 10 ** 15
s = 0
ar = sum(a)
for i in range(n - 1):
	s += a[i]
	ar -= a[i]
	mi = min(mi, abs(ar - s))
print(mi)


n = int(input())
c = list(map(int, input().split()))
sun = sum(c)
can = []
for i in range(n - 1):
	sun -= 2 * c[i]
	can.append(abs(sun))
print(min(can))


import sys
import itertools
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))
N = ini()
A = inl()

def solve():
	B = list(itertools.accumulate(A, initial=0))
	s = 0
	ans = 10 ** 12
	for i in range(N - 1, 0, -1):
		s += A[i]
		ans = min(ans, abs(s - B[i]))
	return ans
print(solve())


N = int(input())
a = list(map(int, input().split()))
cum = [0]
for i in range(N):
	cum.append(cum[-1] + a[i])
ans = 10 ** 20
for i in range(1, N):
	tmp = abs(cum[-1] - cum[i] - cum[i])
	ans = min(ans, tmp)
print(ans)


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


n = int(input())
a = list(map(int, input().split()))
l = a[0]
r = sum(a) - l
ans = abs(l - r)
for i in range(1, n - 1):
	l += a[i]
	r -= a[i]
	if abs(l - r) <= ans:
		ans = abs(l - r)
print(ans)


n = int(input())
a = list(map(int, input().split()))
X = sum(a)
ans = []
snuke = 0
for i in range(n - 1):
	snuke += a[i]
	ans.append(abs(X - 2 * snuke))
print(min(ans))


N = int(input())
a = list(map(int, input().split()))
all = sum(a)
su = 0
mi = float('inf')
for i in range(N - 1):
	su = su + a[i]
	if abs(all - 2 * su) < mi:
		mi = abs(all - 2 * su)
print(mi)


N = int(input())
A = list(map(int, input().split()))
tot = sum(A)
b = []
x = 0
for i in range(N - 1):
	x += A[i]
	b.append(abs(2 * x - tot))
print(min(b))


n = int(input())
a = list(map(int, input().split()))
snuke = sum(a)
arai = 0
ans = 10 ** 20
for i in range(n - 1):
	snuke -= a[i]
	arai += a[i]
	ans = min(ans, abs(snuke - arai))
print(ans)


n = int(input())
l = list(map(int, input().split()))
su = sum(l)
l.pop()
a = 0
x = 99999999999999999999
for i in l:
	a += i
	b = su - a
	c = abs(a - b)
	if c < x:
		x = c
print(x)


n = int(input())
a = list(map(int, input().split()))
v = sum(a)
ans = []
x = 0
for i in range(n - 1):
	x += a[i]
	ans.append(abs(2 * x - v))
print(min(ans))


N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float('inf')
for a in A[:-1]:
	S -= 2 * a
	if abs(S) < ans:
		ans = abs(S)
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
s = sum(l)
a = 0
ans = 10 ** 100
for i in range(n - 1):
	s -= l[i]
	a += l[i]
	ans = min(ans, abs(a - s))
print(ans)


from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a = list(accumulate(a))
ans = 10 ** 10
for i in range(n - 1):
	ans = min(ans, abs(a[i] - a[-1] + a[i]))
print(ans)


n = int(input())
A = list(map(int, input().split()))
ans = 10 ** 20
sumA = sum(A)
x = 0
for i in range(n - 1):
	x += A[i]
	ans = min(ans, abs(sumA - x * 2))
print(ans)


N = int(input())
a = list(map(int, input().strip().split()))
s_l = []
s = 0
for n in range(N):
	s += a[n]
	s_l.append(s)
MIN = 10 ** 15
for n in range(N - 1):
	MIN = min(MIN, abs(s - s_l[n] * 2))
print(MIN)


(n, *a) = map(int, open(0).read().split())
total = sum(a)
ans = 10 ** 18
dt = 0
for i in range(n - 1):
	dt += a[i]
	ans = min(ans, abs(total - dt - dt))
print(ans)


n = int(input())
a = list(map(int, input().split()))
rui = []
rui.append(a[0])
for x in range(1, n):
	b = rui[-1] + a[x]
	rui.append(b)
ans = []
for y in range(n - 1):
	ans.append(abs(rui[n - 1] - rui[y] - rui[y]))
print(min(ans))


n = int(input())
a = [int(i) for i in input().split()]
l = a[0]
m = sum(a) - a[0]
mi = abs(m - l)
for i in range(1, n - 1):
	l += a[i]
	m -= a[i]
	mi = min(mi, abs(m - l))
print(mi)


n = int(input())
A = list(map(int, input().split()))
if n == 2:
	print(abs(A[0] - A[1]))
	return
cum_sum = [0]
for a in A:
	cum_sum.append(cum_sum[-1] + a)
ans = 10 ** 9 + 1
for x in cum_sum[1:-1]:
	y = cum_sum[-1] - x
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
al = list(map(int, input().split()))
bl = [0] * (n + 1)
cl = [0] * (n - 1)
for i in range(n):
	bl[i + 1] = al[i] + bl[i]
for j in range(1, n):
	cl[j - 1] = abs(bl[j] - (bl[n] - bl[j]))
print(min(cl))


N = int(input())
a = list(map(int, input().split()))
li = []
e = sum(a)
for i in range(N - 1):
	e -= 2 * a[i]
	li.append(abs(e))
print(min(li))


import math
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
t = 0
minimum = math.inf
for i in range(N - 1):
	t += a[i]
	s -= a[i]
	minimum = min(minimum, abs(s - t))
print(minimum)


n = int(input())
(*l,) = map(int, input().split())
x = 0
y = sum(l)
xy = [10 ** 15] * n
for i in range(n - 1):
	x += l[i]
	y -= l[i]
	xy[i] = abs(x - y)
print(min(xy))


n = int(input())
a_l = list(map(int, input().split()))
ans = float('inf')
x = 0
X = sum(a_l)
for a in a_l[:-1]:
	x += a
	ans = min(ans, abs(X - 2 * x))
print(ans)


import sys
from itertools import accumulate
n = int(input())
a = list(accumulate(map(int, sys.stdin.readline().split())))
sa = a.pop()
print(min((abs(sa - 2 * i) for i in a)))


import sys

def solve(N: int, a: 'List[int]'):
	from itertools import accumulate
	s = sum(a)
	return min((abs(s - 2 * aa) for aa in accumulate(a[:-1])))

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	a = [int(next(tokens)) for _ in range(N)]
	print(solve(N, a))

def test():
	import doctest
	doctest.testmod()

def __starting_point():
	main()
__starting_point()


N = int(input())
A = list(map(int, input().split()))
res = 10 ** 15
cnt = 0
s = sum(A)
for a in A[:-1]:
	cnt += a
	res = min(res, abs(s - 2 * cnt))
print(res)


n = int(input())
xs = list(map(int, input().split()))
for i in range(1, n):
	xs[i] = xs[i] + xs[i - 1]
print(min([abs(xs[i] - (xs[-1] - xs[i])) for i in range(0, n - 1)]))


from itertools import *
input()
(*a, s) = accumulate(map(int, input().split()))
print(min((abs(s - x * 2) for x in a)))


with open(0) as f:
	(N, *a) = list(map(int, f.read().split()))
score = -sum(a[1:]) + a[0]
ans = abs(score)
for x in a[1:N - 1]:
	score += 2 * x
	ans = min(ans, abs(score))
print(ans)


n = int(input())
A = list(map(int, input().split()))
S = sum(A)
x = A[0]
y = S - x
xy_min = abs(x - y)
for i in range(1, n - 1):
	x += A[i]
	y = S - x
	xy = abs(x - y)
	if xy < xy_min:
		xy_min = xy
print(xy_min)


N = int(input())
a = list(map(int, input().split()))
x = 0
y = sum(a)
d = float('INF')
for i in range(N - 1):
	x += a[i]
	y -= a[i]
	d = min(d, abs(x - y))
print(d)


n = int(input())
a = list(map(int, input().split()))
s = [0] * (n + 1)
for i in range(n):
	s[i + 1] += a[i] + s[i]
ans = float('inf')
for i in range(1, n):
	x = s[i]
	y = s[n] - s[i]
	ans = min(ans, abs(x - y))
print(ans)


from itertools import accumulate as ac
n = int(input())
l = list(ac(map(int, input().split())))
a = l[-1]
print(min((abs(a - 2 * i) for i in l[:-1])))


N = int(input())
A = list(map(int, input().split()))
X = sum(A)
x = 0
ans = 2100000007
for i in range(N):
	x += A[i]
	if i + 1 < N:
		ans = min(ans, abs(X - 2 * x))
print(ans)


n = int(input())
a = [int(x) for x in input().rstrip().split()]
ruiseki = [0]
for i in range(n):
	ruiseki.append(ruiseki[i] + a[i])
ans = float('inf')
last = ruiseki[len(ruiseki) - 1]
for i in range(1, len(ruiseki) - 1):
	now = last - ruiseki[i]
	ans = min(ans, abs(ruiseki[i] - now))
print(ans)


N = int(input())
A = list(map(int, input().split()))
S = sum(A)
snk = 0
arigm = S
ans = 1e+20
for i in range(N - 1):
	snk += A[i]
	arigm -= A[i]
	ans = min(abs(snk - arigm), ans)
print(ans)


(n, *a) = map(int, open(0).read().split())
ans = 10 ** 100
b = sum(a)
c = 0
for i in a[:-1]:
	c += i
	b -= i
	ans = min(ans, abs(b - c))
print(ans)


N = int(input())
a = list(map(int, input().split()))
for i in range(1, N):
	a[i] += a[i - 1]
print(min([abs(a[N - 1] - 2 * a[i]) for i in range(N - 1)]))


N = int(input())
a = list(map(int, input().split()))
sa = a[:]
for i in range(N - 1):
	sa[i + 1] += sa[i]
diff = float('inf')
for i in range(N - 1):
	if abs(sa[i] - (sa[-1] - sa[i])) < diff:
		diff = abs(sa[i] - (sa[-1] - sa[i]))
print(diff)


N = int(input())
L = list(map(int, input().split()))
sums = 0
a = sum(L)
mina = 10 ** 10
for i in range(N - 1):
	a -= 2 * L[i]
	mina = min(mina, abs(a))
print(mina)


n = int(input())
l = list(map(int, input().split()))
(a, b) = (l[0], sum(l[1:]))
m = abs(a - b)
for v in l[1:-1]:
	a += v
	b -= v
	m = min(m, abs(a - b))
print(m)


import sys
import numpy as np
stdin = sys.stdin

def ns():
	return stdin.readline().rstrip()

def ni():
	return int(stdin.readline().rstrip())

def nm():
	return list(map(int, stdin.readline().split()))

def nl():
	return list(map(int, stdin.readline().split()))

def main():
	n = ni()
	A = nl()
	cumA = np.cumsum(A)
	total = cumA[-1]
	ans = 10 ** 10000
	for a in cumA[:-1]:
		ans = min(ans, abs(a - (total - a)))
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
ans = 2 * 10 ** 14 + 1
s = sum(a)
x = 0
y = s
for i in range(n - 1):
	x += a[i]
	y -= a[i]
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
A = list(map(int, input().split()))
ans = 10 ** 50
(x, y) = (0, sum(A))
for i in range(n - 1):
	x += A[i]
	y -= A[i]
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
a = list(map(int, input().split()))
sa = [0 for i in range(n)]
sc = sum(a)
c = 0
for i in range(n):
	c += a[i]
	sa[i] = c
ans = 10 ** 10
for i in range(1, n):
	x = sc - sa[i - 1]
	v = abs(x - sa[i - 1])
	ans = min(ans, v)
print(ans)


N = int(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):
	a = A[i]
	x += a
	y -= a
	dif = abs(x - y)
	if dif < ans:
		ans = dif
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = n * 10 ** 9
s = sum(a)
M = 0
for i in range(n - 1):
	M += a[i]
	if abs(s - 2 * M) < m:
		m = abs(s - 2 * M)
print(m)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
c = 0
m = 10000000000000000
for i in range(n - 1):
	c += l[i]
	d = s - c
	a = abs(d - c)
	m = min(m, a)
print(m)


n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
res = 10 ** 10
tmp_sum = 0
for i in range(n - 1):
	tmp_sum += a[i]
	res = min(res, abs(tmp_sum - (sum_a - tmp_sum)))
print(res)


n = int(input())
l = list(map(int, input().split()))
sum_l = sum(l)
X = 0
ans = 10 ** 10
for i in range(n - 1):
	X += l[i]
	ans = min(ans, abs(sum_l - 2 * X))
print(ans)


N = int(input())
A = list(map(int, input().split()))
s = [0] * (N + 1)
for i in range(N - 1):
	s[i + 1] = s[i] + A[i]
ans = 10 ** 10
for i in range(1, N):
	diff = abs(s[N - 1] + A[-1] - s[i] - s[i])
	ans = min(ans, diff)
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = 0
l = sum(a)
r = []
for i in a[:-1]:
	s += i
	k = abs(l - 2 * s)
	r.append(k)
r.sort()
print(r[0])


n = int(input())
a = list(map(int, input().split()))
p = sum(a)
ans = []
sunu = 0
for i in range(n - 1):
	sunu += a[i]
	ans.append(abs(p - 2 * sunu))
print(min(ans))


from itertools import accumulate
N = int(input())
A = tuple(accumulate(map(int, input().split())))
x = A[-1]
y = A[0]
ans = abs(x - y - y)
for a in A[:-1]:
	ans = min(ans, abs(x - a - a))
print(ans)


a = int(input())
c = list(map(int, input().split()))
su = sum(c)
diff = 10000000000.0
cc = 0
for x in range(a - 1):
	cc += c[x]
	diff = min(diff, abs(su - 2 * cc))
print(diff)


n = int(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)


n = int(input())
a = list(map(int, input().split()))
li = [a[0]]
for i in range(n - 1):
	li.append(li[i] + a[i + 1])
b = []
for i in range(n - 1):
	b.append(abs(li[-1] - li[i] * 2))
print(min(b))


n = int(input())
a = list(map(int, input().split()))
(f, b, c) = (0, sum(a), float('inf'))
for i in range(n - 1):
	(f, b) = (f + a[i], b - a[i])
	c = min(c, abs(f - b))
print(c)


n = int(input())
A = list(map(int, input().split()))
ans = set()
for i in range(1, n):
	A[i] += A[i - 1]
for i in range(n - 1):
	ans.add(abs(A[-1] - A[i] - A[i]))
print(min(ans))


n = int(input())
a = list(map(int, input().split()))
f = 0
b = sum(a)
m = abs(a[0] - sum(a[1:]))
for i in range(n - 1):
	f += a[i]
	b -= a[i]
	m = min(m, abs(f - b))
print(m)


from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
if n == 2:
	print(abs(A[0] - A[1]))
	return
B = list(accumulate(A))
ans = float('inf')
y = 0
for i in range(n - 1, 0, -1):
	x = B[i - 1]
	y += A[i]
	ans = min(ans, abs(x - y))
print(ans)


n = int(input())
a = list(map(int, input().split()))
sm = sum(a)
s = a.pop(0)
mn = abs(sm - s * 2)
for i in a[:-1]:
	s += i
	mn = min(mn, abs(sm - s * 2))
print(mn)


n = int(input())
a = list(map(int, input().split()))
l = sum(a)
r = 0
ans = 10 ** 20
for i in a[:-1]:
	l -= i
	r += i
	ans = min(ans, abs(l - r))
print(ans)


import itertools
n = int(input())
a = list(map(int, input().split(' ')))
mini = 10 ** 10
suma = list(itertools.accumulate(a))
for i in range(0, n - 1):
	mini = min(mini, abs(suma[-1] - suma[i] * 2))
print(mini)


n = int(input())
a = [int(x) for x in input().split()]
sum_a = sum(a)
l = []
x = 0
for a_ in a[:n - 1]:
	x += a_
	l.append(abs(sum_a - x * 2))
res = min(l)
print(res)


from itertools import accumulate as acc
input()
S = tuple(acc(map(int, input().split())))
print(min((abs(S[-1] - 2 * x) for x in S[:-1])))


n = int(input())
L = list(map(int, input().split()))
li = [0]
for i in range(n):
	li.append(li[i] + L[i])
sumL = sum(L)
ans = 10 ** 10
for i in range(1, n):
	diff = abs(li[i] - (sumL - li[i]))
	ans = min(ans, diff)
print(ans)


n = int(input())
A = list(map(int, input().split()))
X = sum(A)
x = 0
c = 2 * 10 ** 14
for i in range(n - 1):
	x += A[i]
	s = abs(X - 2 * x)
	c = min(c, s)
print(c)


N = int(input())
A = list(map(int, input().split()))
max_ = sum(A)
tmp = 0
result = []
for i in range(N - 1):
	tmp += A[i]
	result.append(abs(max_ - 2 * tmp))
print(min(result))


INF = 10 ** 18
N = int(input())
A = list(map(int, input().split()))
res = INF
t = sum(A)
s = 0
for a in A[:-1]:
	s += a
	res = min(res, abs(t - s - s))
print(res)


N = int(input())
an = list(map(int, input().split()))
s = sum(an)
b = an[0]
l = []
a = abs(s - 2 * b)
for i in range(1, N - 1):
	b = b + an[i]
	a = min(a, abs(s - 2 * b))
print(a)


n = int(input())
a = list(map(int, input().split()))
ss = sum(a)
ans = 10 ** 18
x = 0
for i in range(n - 1):
	x += a[i]
	ans = min(ans, abs(ss - 2 * x))
print(ans)