def main():

    n = int(eval(input()))

    a = [int(x) for x in input().split()]

    for i in range(1, n):

        a[i] += a[i - 1]

    answer = float("inf")

    for i in range(n - 1):

        answer = min(answer, abs(a[-1] - 2 * a[i]))

    print(answer)





if __name__ == '__main__':

    main()



def main():

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

    print(ans)





if __name__ == '__main__':

    main()



def main():
    n = int(eval(input()))
    a = [int(x) for x in input().split()]
    for i in range(1, n):
        a[i] += a[i - 1]
    answer = float("inf")
    for i in range(n - 1):
        answer = min(answer, abs(a[-1] - 2 * a[i]))
    print(answer)


if __name__ == "__main__":
    main()

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


if __name__ == "__main__":
    main()

-    a = [int(x) for x in input().split()] +    a = list(map(int, input().split())) -    answer = float("inf") +    ans = float("inf") -        answer = min(answer, abs(a[-1] - 2 * a[i])) -    print(answer) +        ans = min(ans, abs(a[-1] - 2 * a[i])) +    print(ans)