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()]

    aDiff  = [0]*(iN-1)

    iD = sum(aA)

    iF = 0

    for i in range(iN-1):

        iF += aA[i]

        aDiff[i] = abs(iD - 2*iF)

    print((min(aDiff)))

解()

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()]
    aDiff = [0] * (iN - 1)
    iD = sum(aA)
    iF = 0
    for i in range(iN - 1):
        iF += aA[i]
        aDiff[i] = abs(iD - 2 * iF)
    print((min(aDiff)))


解()

+    aDiff = [0] * (iN - 1) -    minDiff = 10**9 * 2 -    for a in aA[:-1]: -        iF += a -        thisDiff = abs(iD - 2 * iF) -        minDiff = min(minDiff, thisDiff) -    print(minDiff) +    for i in range(iN - 1): +        iF += aA[i] +        aDiff[i] = abs(iD - 2 * iF) +    print((min(aDiff)))