def main():

  n = int(eval(input()))

  a = list(input_list())

  sa = sum(a)

  ans = 10**10

  r = 0

  for v in list(a)[:-1]:

    r += v

    ans = min(ans, abs(sa - (2*r)))

  print(ans)



def input_list():

  return list(map(int, input().split()))



def input_list_str():

  return list(map(str, input().split()))



def lcm_base(x, y):

    return (x * y) // fractions.gcd(x, y)



def lcm_list(numbers):

    return reduce(lcm_base, numbers, 1)



def gcd(*numbers):

    return reduce(fractions.gcd, numbers)



def gcd_list(numbers):

    return reduce(fractions.gcd, numbers)



import math

import fractions

from functools import reduce

main()
import collections





def main():

    n = int(eval(input()))

    a = input_list()

    sum_a = sum(a)

    wa = []

    for i, v in enumerate(a):

        if i == 0:

            wa.append(v)

        else:

            wa.append(v+wa[i-1])

    ans = float('inf')

    for i in range(n-1):

        ans = min(ans, abs(sum_a-(wa[i]*2)))

    print(ans)





def input_list():

    return list(map(int, input().split()))





if __name__ == '__main__':

    main()

def main():
    n = int(eval(input()))
    a = list(input_list())
    sa = sum(a)
    ans = 10**10
    r = 0
    for v in list(a)[:-1]:
        r += v
        ans = min(ans, abs(sa - (2 * r)))
    print(ans)


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


import math
import fractions
from functools import reduce

main()

import collections


def main():
    n = int(eval(input()))
    a = input_list()
    sum_a = sum(a)
    wa = []
    for i, v in enumerate(a):
        if i == 0:
            wa.append(v)
        else:
            wa.append(v + wa[i - 1])
    ans = float("inf")
    for i in range(n - 1):
        ans = min(ans, abs(sum_a - (wa[i] * 2)))
    print(ans)


def input_list():
    return list(map(int, input().split()))


if __name__ == "__main__":
    main()

+import collections + + -    a = list(input_list()) -    sa = sum(a) -    ans = 10**10 -    r = 0 -    for v in list(a)[:-1]: -        r += v -        ans = min(ans, abs(sa - (2 * r))) +    a = input_list() +    sum_a = sum(a) +    wa = [] +    for i, v in enumerate(a): +        if i == 0: +            wa.append(v) +        else: +            wa.append(v + wa[i - 1]) +    ans = float("inf") +    for i in range(n - 1): +        ans = min(ans, abs(sum_a - (wa[i] * 2))) -def input_list_str(): -    return list(map(str, input().split())) - - -def lcm_base(x, y): -    return (x * y) // fractions.gcd(x, y) - - -def lcm_list(numbers): -    return reduce(lcm_base, numbers, 1) - - -def gcd(*numbers): -    return reduce(fractions.gcd, numbers) - - -def gcd_list(numbers): -    return reduce(fractions.gcd, numbers) - - -import math -import fractions -from functools import reduce - -main() +if __name__ == "__main__": +    main()