import sys

input = sys.stdin.readline



n = int(eval(input()))

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

s = [None] * n; s[0] = a[0]

for i in range(n-1): s[i+1] = s[i] + a[i+1]



mixi = abs(s[0] - (s[n-1] - s[0]))

for i in range(1, n-1): mixi = min(mixi, abs(s[i] - (s[n-1] - s[i])))   # 全部取るのはダメ



print(mixi)
import sys



n, *a = list(map(int, sys.stdin.read().split()))



def main():

    x = 0

    y = sum(a)

    res = []

    for i in range(n-1):

        x += a[i]

        y -= a[i]

        res.append(abs(x - y))



    return min(res)



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

input = sys.stdin.readline
n = int(eval(input()))
a = [int(a) for a in input().split()]
s = [None] * n
s[0] = a[0]
for i in range(n - 1):
    s[i + 1] = s[i] + a[i + 1]
mixi = abs(s[0] - (s[n - 1] - s[0]))
for i in range(1, n - 1):
    mixi = min(mixi, abs(s[i] - (s[n - 1] - s[i])))  # 全部取るのはダメ
print(mixi)

import sys

n, *a = list(map(int, sys.stdin.read().split()))


def main():
    x = 0
    y = sum(a)
    res = []
    for i in range(n - 1):
        x += a[i]
        y -= a[i]
        res.append(abs(x - y))
    return min(res)


if __name__ == "__main__":
    ans = main()
    print(ans)

-input = sys.stdin.readline -n = int(eval(input())) -a = [int(a) for a in input().split()] -s = [None] * n -s[0] = a[0] -for i in range(n - 1): -    s[i + 1] = s[i] + a[i + 1] -mixi = abs(s[0] - (s[n - 1] - s[0])) -for i in range(1, n - 1): -    mixi = min(mixi, abs(s[i] - (s[n - 1] - s[i])))  # 全部取るのはダメ -print(mixi) +n, *a = list(map(int, sys.stdin.read().split())) + + +def main(): +    x = 0 +    y = sum(a) +    res = [] +    for i in range(n - 1): +        x += a[i] +        y -= a[i] +        res.append(abs(x - y)) +    return min(res) + + +if __name__ == "__main__": +    ans = main() +    print(ans)