import sys

from itertools import accumulate



sys.setrecursionlimit(10 ** 8)

ini = lambda: int(sys.stdin.readline())

inm = lambda: map(int, sys.stdin.readline().split())

inl = lambda: list(inm())

ins = lambda: sys.stdin.readline().rstrip()

debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))



n = ini()

a = inl()





def solve():

    al = list(accumulate(a))

    ar = list(reversed(list(accumulate(a[::-1]))))

    ans = 1 << 60

    for i in range(1, n):

        r = abs(al[i - 1] - ar[i])

        ans = min(ans, r)



    return ans





print(solve())

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("\033[33m", *a, "\033[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())

import sys
from itertools import accumulate

sys.setrecursionlimit(10**8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
n = ini()
a = inl()


def solve():
    al = list(accumulate(a))
    ar = list(reversed(list(accumulate(a[::-1]))))
    ans = 1 << 60
    for i in range(1, n):
        r = abs(al[i - 1] - ar[i])
        ans = min(ans, r)
    return ans


print(solve())

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("\033[33m", *a, "\033[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())

-from itertools import accumulate +import itertools -inm = lambda: map(int, sys.stdin.readline().split()) -inl = lambda: list(inm()) +inl = lambda: [int(x) for x in sys.stdin.readline().split()] -n = ini() -a = inl() +N = ini() +A = inl() -    al = list(accumulate(a)) -    ar = list(reversed(list(accumulate(a[::-1])))) -    ans = 1 << 60 -    for i in range(1, n): -        r = abs(al[i - 1] - ar[i]) -        ans = min(ans, r) +    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]))