INF = float('inf')





def main():

    N, *a = list(map(int, open(0).read().split()))

    ans = INF

    tmp = 0

    total = sum(a)

    for i in range(N - 1):

        tmp += a[i]

        ans = min(ans, abs(2 * tmp - total))

    print(ans)

    return





main()

from itertools import accumulate





def main():

    N, *a = list(map(int, open(0).read().split()))

    a = list(accumulate(a))

    total = a[-1]

    print((min(abs(2 * a[i] - total) for i in range(N - 1))))

    return





main()

INF = float("inf")


def main():
    N, *a = list(map(int, open(0).read().split()))
    ans = INF
    tmp = 0
    total = sum(a)
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - total))
    print(ans)
    return


main()

from itertools import accumulate


def main():
    N, *a = list(map(int, open(0).read().split()))
    a = list(accumulate(a))
    total = a[-1]
    print((min(abs(2 * a[i] - total) for i in range(N - 1))))
    return


main()

-INF = float("inf") +from itertools import accumulate -    ans = INF -    tmp = 0 -    total = sum(a) -    for i in range(N - 1): -        tmp += a[i] -        ans = min(ans, abs(2 * tmp - total)) -    print(ans) +    a = list(accumulate(a)) +    total = a[-1] +    print((min(abs(2 * a[i] - total) for i in range(N - 1))))