

def 解():

    iN = int(eval(input()))

    aA = [int(_) for _ in input().split()]

    #itertools をつかわず 累積和でやってみると？

    aAc = [0]*iN

    aAc[0] = aA[0]

    for i in range(1,iN):

        aAc[i] = aAc[i-1] + aA[i]

    iD = aAc[-1]

    minDiff = 10**9 *2

    for i in range(iN-1):

        minDiff = min(minDiff,abs(iD-2*aAc[i]))

    print(minDiff)

解()

def 解():

    iN = int(eval(input()))

    aA = [int(_) for _ in input().split()]



    iD = sum(aA)

    iF = 0

    minDiff = 10**9 * 2

    for a in aA[:-1] :

        iF += a

        thisDiff = abs(iD - 2*iF)

        minDiff = min(minDiff , thisDiff)

    print(minDiff)

解()

def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]
    # itertools をつかわず 累積和でやってみると？
    aAc = [0] * iN
    aAc[0] = aA[0]
    for i in range(1, iN):
        aAc[i] = aAc[i - 1] + aA[i]
    iD = aAc[-1]
    minDiff = 10**9 * 2
    for i in range(iN - 1):
        minDiff = min(minDiff, abs(iD - 2 * aAc[i]))
    print(minDiff)


解()

def 解():
    iN = int(eval(input()))
    aA = [int(_) for _ in input().split()]
    iD = sum(aA)
    iF = 0
    minDiff = 10**9 * 2
    for a in aA[:-1]:
        iF += a
        thisDiff = abs(iD - 2 * iF)
        minDiff = min(minDiff, thisDiff)
    print(minDiff)


解()

-    # itertools をつかわず 累積和でやってみると？ -    aAc = [0] * iN -    aAc[0] = aA[0] -    for i in range(1, iN): -        aAc[i] = aAc[i - 1] + aA[i] -    iD = aAc[-1] +    iD = sum(aA) +    iF = 0 -    for i in range(iN - 1): -        minDiff = min(minDiff, abs(iD - 2 * aAc[i])) +    for a in aA[:-1]: +        iF += a +        thisDiff = abs(iD - 2 * iF) +        minDiff = min(minDiff, thisDiff)