def main():

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    s = [0] * (N + 1)

    for i in range(0, N):

        s[i+1] = s[i] + A[i]

    ans = (1 << 63) - 1

    for j in range(1, N):

        left = s[j] - s[0]

        right = s[N] - s[j]

        ans = min(ans, abs(right - left))

    print(ans)





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    from itertools import accumulate

    acc = [a for a in accumulate([0] + A)]

    ans = acc[-1]

    for i in range(1, N+1):

        a = acc[i]

        b = acc[N] - acc[i]

        v = abs(a-b)

        ans = min(ans, v)

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    s = [0] * (N + 1)
    for i in range(0, N):
        s[i + 1] = s[i] + A[i]
    ans = (1 << 63) - 1
    for j in range(1, N):
        left = s[j] - s[0]
        right = s[N] - s[j]
        ans = min(ans, abs(right - left))
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    from itertools import accumulate

    acc = [a for a in accumulate([0] + A)]
    ans = acc[-1]
    for i in range(1, N + 1):
        a = acc[i]
        b = acc[N] - acc[i]
        v = abs(a - b)
        ans = min(ans, v)
    print(ans)


if __name__ == "__main__":
    main()

-    s = [0] * (N + 1) -    for i in range(0, N): -        s[i + 1] = s[i] + A[i] -    ans = (1 << 63) - 1 -    for j in range(1, N): -        left = s[j] - s[0] -        right = s[N] - s[j] -        ans = min(ans, abs(right - left)) +    from itertools import accumulate + +    acc = [a for a in accumulate([0] + A)] +    ans = acc[-1] +    for i in range(1, N + 1): +        a = acc[i] +        b = acc[N] - acc[i] +        v = abs(a - b) +        ans = min(ans, v)