import sys





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n = int(input().rstrip('\n'))

    a = list(map(int, input().rstrip('\n').split()))

    st = sum(a)

    t = 0

    abs_t = 10 ** 10

    for i in range(n-1):

        t += a[i]

        st -= a[i]

        abs_t = min(abs_t, abs(st - t))

    print(abs_t)





if __name__ == '__main__':

    solve()

import sys





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

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

    sa = sum(a)

    t = 0

    mt = 10 ** 20

    for v in a:

        t += v

        mt = min(mt, abs(sa - t - t))

    print(mt)





if __name__ == '__main__':

    solve()

import sys


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n = int(input().rstrip("\n"))
    a = list(map(int, input().rstrip("\n").split()))
    st = sum(a)
    t = 0
    abs_t = 10**10
    for i in range(n - 1):
        t += a[i]
        st -= a[i]
        abs_t = min(abs_t, abs(st - t))
    print(abs_t)


if __name__ == "__main__":
    solve()

import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    sa = sum(a)
    t = 0
    mt = 10**20
    for v in a:
        t += v
        mt = min(mt, abs(sa - t - t))
    print(mt)


if __name__ == "__main__":
    solve()

-    input = sys.stdin.readline +    readline = sys.stdin.buffer.readline -    n = int(input().rstrip("\n")) -    a = list(map(int, input().rstrip("\n").split())) -    st = sum(a) +    n = int(readline()) +    a = list(map(int, readline().split())) +    sa = sum(a) -    abs_t = 10**10 -    for i in range(n - 1): -        t += a[i] -        st -= a[i] -        abs_t = min(abs_t, abs(st - t)) -    print(abs_t) +    mt = 10**20 +    for v in a: +        t += v +        mt = min(mt, abs(sa - t - t)) +    print(mt)