# ABC067C - Splitting Pile

def main():

    n = int(eval(input()))

    lst = tuple(map(int, input().rstrip().split()))

    cur, total, ans = 0, sum(lst), float("inf")

    for i in lst[:-1]:

        cur += i

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

    print(ans)





if __name__ == "__main__":

    main()
# ARC078C - Splitting Pile (ABC067C)

from itertools import accumulate





def main():

    n = int(eval(input()))

    lst = tuple(accumulate(list(map(int, input().rstrip().split()))))

    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])

    print(ans)





if __name__ == "__main__":

    main()
# ABC067C - Splitting Pile
def main():
    n = int(eval(input()))
    lst = tuple(map(int, input().rstrip().split()))
    cur, total, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        cur += i
        ans = min(ans, abs(total - cur * 2))
    print(ans)


if __name__ == "__main__":
    main()

# ARC078C - Splitting Pile (ABC067C)
from itertools import accumulate


def main():
    n = int(eval(input()))
    lst = tuple(accumulate(list(map(int, input().rstrip().split()))))
    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])
    print(ans)


if __name__ == "__main__":
    main()

-# ABC067C - Splitting Pile +# ARC078C - Splitting Pile (ABC067C) +from itertools import accumulate + + -    lst = tuple(map(int, input().rstrip().split())) -    cur, total, ans = 0, sum(lst), float("inf") -    for i in lst[:-1]: -        cur += i -        ans = min(ans, abs(total - cur * 2)) +    lst = tuple(accumulate(list(map(int, input().rstrip().split())))) +    ans = min(abs(lst[-1] - i * 2) for i in lst[:-1])