CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
N, C = list(map(int, input().split()))
table = [[0] * C for i in range(2 * 10 ** 5 + 2)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    table[2 * s - 1][c - 1] = 1
    table[2 * t][c - 1] = -1

ans = [0] * (2 * 10 ** 5 + 2)
for i in range(1, 2 * 10 ** 5 + 2):
    for j in range(C):
        if table[i - 1][j] == 1 and table[i][j] == 0:
            table[i][j] = 1
    ans[i] = sum([abs(x) for x in table[i]])

print((max(ans[1:])))


# Optimized solution
#!/usr/bin/env python3
N, C = list(map(int, input().split()))
table = [[0] * C for i in range(10 ** 5 + 1)]
for i in range(N):
    s, t, c = list(map(int, input().split()))
    table[s - 1][c - 1] += 1
    table[t - 1][c - 1] -= 1

imos = [0] * (10 ** 5 + 1)
for i in range(10 ** 5 + 1):
    for j in range(C):
        if table[i][j] == 1:
            imos[i] += 1
        if table[i][j] == -1:
            imos[i + 1] -= 1

ans = 0
for i in range(1, 10 ** 5 + 1):
    imos[i] += imos[i - 1]
    ans = max(ans, imos[i])

print(ans)
# Original solution
n, c = list(map(int, input().split()))
MAX_COLS = 10**5
table = [[0 for _ in range(MAX_COLS)] for _ in range(c)]

for _ in range(n):
    s, t, i = list(map(int, input().split()))
    for j in range(s - 1, t - 1):
        table[i - 1][j] = 1

for i in range(c):
    for j in range(MAX_COLS - 1):
        if table[i][j] == 0 and table[i][j + 1] == 1:
            table[i][j] = 1

res = 0
for j in range(MAX_COLS):
    count = 0
    for i in range(c):
        count += table[i][j]
    res = max(res, count)
print(res)

# Optimized solution
n, c = list(map(int, input().split()))
MAX_COLS = 10**5
table = [[0 for _ in range(MAX_COLS)] for _ in range(c)]

for _ in range(n):
    s, t, i = list(map(int, input().split()))
    for j in range(max(0, s - 2), t - 1):
        table[i - 1][j] = 1

res = 0
for j in range(MAX_COLS):
    count = 0
    for i in range(c):
        count += table[i][j]
    res = max(res, count)
print(res)
# Original solution
N,C = list(map(int, input().split()))
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = list(map(int, input().split()))

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(31):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)

# Optimized solution
N,C = list(map(int, input().split()))
s =[0]*N
t =[0]*N
c =[0]*N
for i in range(N):
    s[i],t[i],c[i] = list(map(int, input().split()))

imos = [[0]*int(1e5+20) for _ in range(31)]
for i in range(N):
    imos[c[i]][s[i]]+=1
    imos[c[i]][t[i]+1]-=1

ans = 0
for i in range(1,int(1e5+10)):
    sm = 0
    for j in range(C+1):
        imos[j][i]=imos[j][i-1]+ imos[j][i]
        if imos[j][i] >= 1:
            sm+=1
    ans = max(ans,sm)
print(ans)
# Original solution
def d_recording(N, C, R):
    """
    N:録画する番組の数
    C:テレビが受信できるチャンネルの数
    R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc]
    """
    s = [row[0] for row in R]
    t = [row[1] for row in R]
    c = [row[2] for row in R]

    # いつまで録画機を動かすか。0.5を単位時間とするので*2
    # 時刻を0からスタートさせるので+2
    l = max(t) * 2 + 2
    sm = [0 for _ in range(l)]  # ある時刻に動いている録画機の数が格納される

    for i in range(1, C + 1):
        tt = [0 for _ in range(l)]  # チャンネルiを録画しているか否かを格納
        # 累積和を取る
        for j in range(N):
            if c[j] == i:
                # 録画開始時刻の0.5前を+1,終了時刻を-1
                #(終了時刻は含まないという録画機の条件より、このようにする)
                tt[s[j] * 2 - 1] += 1
                tt[t[j] * 2] -= 1
        for j in range(1, l):
            tt[j] += tt[j - 1]
        # あるチャンネルを録画している時間帯では、録画機を1個使わねばならない
        for j in range(l):
            if tt[j] > 0:
                sm[j] += 1
    ans = max(sm)
    return ans

N,C = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(N)]
print((d_recording(N, C, R)))

# Optimized solution
def d_recording(N, C, R):
    # N:録画する番組の数
    # C:テレビが受信できるチャンネルの数
    # R:録画する番組の情報 [開始時刻s,終了時刻t,チャンネルc]
    from itertools import accumulate
    start = [row[0] for row in R]
    end = [row[1] for row in R]
    channel_num = [row[2] for row in R]

    # いつまで録画機を動かすか。0.5を単位時間とするので*2
    # 時刻を0からスタートさせるので+2
    l = max(end) * 2 + 2
    running_recorder = [0 for _ in range(l)]  # [k]:ある時刻に動作中の録画機の数

    for channel in range(1, C + 1):
        rec = [0 for _ in range(l)]  # [k]:チャンネルkを録画しているか否か
        # 累積和を取る
        for s, t, c in zip(start, end, channel_num):
            if c == channel:
                # 録画開始時刻の0.5前を+1,終了時刻を-1
                # (終了時刻は含まないという録画機の条件より、このようにする)
                rec[s * 2 - 1] += 1
                rec[t * 2] -= 1
        rec = accumulate(rec)
        # あるチャンネルを録画している時間帯では、録画機を1個使わねばならない
        for j, running in enumerate(rec):
            if running > 0:
                running_recorder[j] += 1
    ans = max(running_recorder)
    return ans

N, C = [int(i) for i in input().split()]
R = [[int(i) for i in input().split()] for j in range(N)]
print((d_recording(N, C, R)))
# Original solution
n, c = list(map(int, input().split()))
T = 10**5+1
l = [[0]*c for _ in range(T)]

for _ in range(n):
    s, t, c_ = list(map(int, input().split()))
    c_ -= 1
    l[s-1][c_] += 1
    l[t][c_]   -= 1

for i in range(1, T):
    for c_ in range(c):
        l[i][c_] += l[i-1][c_]
        l[i-1][c_] = min(1, l[i-1][c_])

ans = 0
for i in range(T):
    ans = max(ans, sum(l[i]))

print(ans)


# Optimized solution
n, c = list(map(int, input().split()))
T = 10**5+1
l = [[0]*c for _ in range(T)]

for _ in range(n):
    s, t, c_ = list(map(int, input().split()))
    c_ -= 1
    for i in range(s-1, t):
        l[i][c_] = 1

ans = 0
for i in range(T):
    ans = max(ans, sum(l[i]))

print(ans)
# Original solution
import sys
input=sys.stdin.buffer.readline
n,c=list(map(int,input().split()))
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=list(map(int,input().split()))
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)


# Optimized solution
import sys
input=sys.stdin.buffer.readline
n,c=list(map(int,input().split()))
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=list(map(int,input().split()))
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)
# Original solution
import sys
from itertools import accumulate

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    # if we can record the programms continuously (ver2)
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    # else:
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]

# ans = max([sum(x) for x in zip(*tbl2)])
# print(ans)

res = 0
for i in range(200002):
    cc = 0
    for j in range(C):
        if tbl2[j][i] == 1:
            cc += 1
    res = max(res, cc)
print(res)


# Optimized solution
import sys
from itertools import accumulate

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    # if we can record the programms continuously (ver2)
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    # else:
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]==2:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

# tmp = [sum(x) for x in zip(*tbl2)]

# res = 0
# for i in range(200002):
#     cc = 0
#     for j in range(C):
#         if tbl2[j][i]:
#             cc += 1
#     res = max(res, cc)
# print(res)
# Original solution
import sys
from itertools import accumulate

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2*s] == -1:
        tbl[c][2*s] = 0
        tbl[c][2*t] = -1
    # if we can record the programms continuously (ver2)
    elif tbl[c][2*t-1] == 1:
        tbl[c][2*t-1] = 0
        tbl[c][2*s-1] = 1
    # else:
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]
for i in range(200002):
     for j in range(C):
         if tbl2[j][i]>1:
          	tbl2[j][i]=1

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)

# tmp = [sum(x) for x in zip(*tbl2)]

# res = 0
# for i in range(200002):
#     cc = 0
#     for j in range(C):
#         if tbl2[j][i]:
#             cc += 1
#     res = max(res, cc)
# print(res)


# Optimized solution
import sys
from itertools import accumulate

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
Rmap = lambda: list(map(int, r().split()))
# set inputs
N, C = R()
STC = [R() for _ in range(N)]
#  0.5sec as one unit
tbl = [[0]*(2*(10**5)+5) for _ in range(C)]

for s, t, c in STC:
    c -= 1
    # if we can record the programms continuously (ver1)
    if tbl[c][2*s] != 0 and tbl[c][2*t-1] != 0:
        tbl[c][2*s] = 0
        tbl[c][2*t-1] = 0
    # if we can record the programms continuously (ver2)
    elif tbl[c][2*s] != 0:
        tbl[c][2*s] += 1
        tbl[c][2*t] -= 1
    # if we can record the programms continuously (ver3)
    elif tbl[c][2*t-1] != 0:
        tbl[c][2*t-1] -= 1
        tbl[c][2*s-1] += 1
    # else:
    else:
        tbl[c][2*s-1] = 1
        tbl[c][2*t] = -1

tbl2 = [list(accumulate(a)) for a in tbl]

ans = max([sum(x) for x in zip(*tbl2)])
print(ans)
# Original solution
_ = eval(input())
a = [int(i) for i in input().split(' ')]
res = 9999999999999999999999999
for i in range(1,len(a)):
    s = sum(a[:i])
    t = sum(a[i:])
    temp = abs(s-t)
    res = min(temp,res)
print(res)

# Optimized solution
import sys

n = int(eval(input()))
a = []
b = input().split(" ")
for i in range(n):
	a.append(int(b[i]))

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

mn = abs(a[n-1] - 2*a[0])
for i in range(1, n-1):
	mn = min(mn, abs(a[n-1] - 2*a[i]))

print(mn)
# Original solution
# ABC067C - Splitting Pile (ARC078C)
def main():
    n = int(eval(input()))
    lst = tuple(map(int, input().rstrip().split()))
    l, r, ans = 0, sum(lst), float("inf")
    for i in lst[:-1]:
        l += i
        r -= i
        ans = min(ans, abs(l - r))
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
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()
# Original solution
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()

# Optimized solution
from itertools import accumulate


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


if __name__ == "__main__":
    main()
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
x=0
lis=[]
for i in range(n-1):
    x+=a[i]
    lis.append(abs(2*x-total))
print((min(lis)))



# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
total=sum(a)
x=0
ans=abs(max(a)-min(a))
for i in range(n-1):
    x+=a[i]
    if abs(2*x-total)<ans:
        ans=abs(2*x-total)
print(ans)
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))

S = sum(a)
arr = [abs(S - 2*sum(a[:i]))   for i in range(1,N)]

print((min(arr)))

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))

S = sum(a)
_min  = 10000000000000000000
x = 0
for i in range(0,N-1):
  x += a[i]
  tmp = abs(S - 2*x)
  if tmp < _min:
    _min = tmp

print(_min)
# Original solution
n,*A=list(map(int,open(0).read().split()))
for i in range(n-1):A[i+1]+=A[i]
print((min(abs(A[n-1]-A[i]*2)for i in range(n-1))))

# Optimized solution
n,*A=list(map(int,open(0).read().split()))
while n>1:n-=1;A[n-1]+=A[n]
print((min(abs(A[0]-e*2)for e in A[1:])))
# Original solution
def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    #N = 1000
    #a = [i for i in range(N)]

    #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]

    summation = []
    sumtemp = sum(a)
    for i in range(len(a)-1):
        tmp1 = sum(a[:(i+1)])
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print((min(summation)))

main()



# Optimized solution
def main():
    N = int(eval(input()))
    a = list(map(int, input().split()))
    #N = 1000
    #a = [i for i in range(N)]

    #summation = [abs(sum(a[:(i+1)]) - sum(a[(i+1):])) for i in range(len(a)-1)]

    summation = []
    sumtemp = sum(a)
    tmp1 = 0
    for i in range(len(a)-1):
        tmp1 += a[i]
        tmp2 = sumtemp - tmp1
        tmp = abs(tmp1 - tmp2)
        summation.append(tmp)
        
    print((min(summation)))

main()
# Original solution
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 2**((self.n-1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = [None]*(2*self.N-1)
        
        # construction
        for i in range(self.N):
            self.v[i + self.N - 1] = lst[i] if i < self.n else self.e
        for i in range(self.N - 2, -1, -1):
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
        
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1
            i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i+2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        assert l < r
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e
        R = self.e
        while left < right:
            if left % 2 == 0: # left is even
                L = self.op(L, self.v[left])
                left += 1
            if right % 2 == 0: # right is even
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1
            left >>= 1
            right >>= 1
        return self.op(L, R)

N = int(eval(input()))
*A, = list(map(int, input().split()))
total = sum(A)
st = SegmentTree(A, lambda x,y:x+y, 0)
ans = 10**18
for i in range(N-1):
    snuke = st.query(0, i+1)
    arai = total - snuke
    ans = min(ans, abs(arai - snuke))
print(ans)

# Optimized solution
N = int(eval(input()))
*A, = list(map(int, input().split()))
total = sum(A)
snuke = 0
ans = 10**18
for i in range(N-1):
    snuke += A[i]
    arai = total - snuke
    ans = min(ans, abs(arai - snuke))
print(ans)
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""


# ARC 078 C  Splitting Pile
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    diff = 10**(9+6)
    for i in range(1, N):
        diff = min(diff, abs(sum(A[:i])-sum(A[i:])))
    return diff


debug = False  # True False
ans = probC()
print(ans)
#for row in ans:
#    print(row)


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""


# ARC 078 C  Splitting Pile
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    sumFormer = A[0]
    sumLatter = sum(A[1:])
    diff = abs(sumFormer-sumLatter)
    dmp(diff,'init')
    for i in range(1, N-1):
        sumFormer += A[i]
        sumLatter -= A[i]
        diff = min(diff, abs(sumFormer-sumLatter))
    return diff


def probC_v1():  # 5/16 AC 残りはTLE
    N = getInt()
    A = getIntList()
    dmp((N, A))
    diff = 10**(9+6)
    for i in range(1, N):
        diff = min(diff, abs(sum(A[:i])-sum(A[i:])))
    return diff


debug = False  # True False
ans = probC()
print(ans)
#for row in ans:
#    print(row)
# Original solution
N = int(eval(input()))
a = list(map(int,input().split()))

cum_sum = [0]*N
cum_sum[0] = a[0]

for i in range(1,N):
	cum_sum[i] = cum_sum[i-1] + a[i]

res = 10**15
for i in range(N-1):
	x = cum_sum[i]
	y = cum_sum[N-1] - cum_sum[i]
	res = min(res, abs(x-y))

print(res)

# Optimized solution
N = int(eval(input()))
a = list(map(int,input().split()))

x = a[0]
y = sum(a[1:])
res = abs(x - y)

for i in range(1, N - 1):
	x += a[i]
	y -= a[i]
	res = min(res, abs(x - y))

print(res)
# Original solution
N = eval(input())
a = list(map(int, input().split()))

all = sum(a)

mini = 10000000000

for i in range(1,N):
    x = sum(a[:i])
    y = all - x 
    ret = abs(x-y)

    if(ret < mini): mini=ret

print(mini)


# Optimized solution
N = eval(input())
a = list(map(int, input().split()))

all = sum(a)

mini = 10000000000

x = 0
y = all

for i in range(0,N-1):
    x += a[i]
    y -= a[i]
    ret = abs(x-y)

    if(ret < mini): mini=ret

print(mini)
# Original solution
# -*- coding: utf-8 -*-
from itertools import combinations

def inpl(): return tuple(map(int, input().split()))

N = int(eval(input()))
A = inpl()
s = sum(A)

X = [sum(A[:i]) for i in range(1, N)]
print((min([abs(2*x - s) for x in X])))

# Optimized solution
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(eval(input()))
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)
# Original solution
# -*- coding:utf-8 -*-
N = int(eval(input()))
a = list(map(int, input().split()))
b = sum(a)
minimum = float('inf')
for tmp in range(1,N):
    c = sum(a[tmp:len(a)])
    d = abs(b-2*c)
    minimum = min(minimum, d)
print(minimum)

# Optimized solution
# -*- coding:utf-8 -*-
N = int(eval(input()))
a = list(map(int, input().split()))
b = sum(a)
c = 0
minimum = float('inf')
for tmp in range(0,N-1):
    c += a[tmp]    
    d = abs(c-(b-c))
    minimum = min(minimum, d)
print(minimum)
# Original solution
#coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

cnt = 0
for t in T:
    for s in S:
        if t == s:
            cnt += 1
            break

print(cnt)



# Optimized solution
#coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

def search_banpei(array, target, cnt):
    tmp = array[len(array)-1]
    array[len(array)-1] = target

    n = 0
    while array[n] != target:
        n += 1

    array[len(array)-1] = tmp
    if n < len(array) - 1 or target == tmp:
        cnt += 1
    return cnt        

def linear_search():  
    cnt = 0
    for t in T:
        for s in S:
            if t == s:
                cnt += 1
                break

def linear_banpei_search():
    cnt = 0
    for target in T:
        cnt = search_banpei(S, target, cnt)
    return cnt

cnt = linear_banpei_search()

print(cnt)
# Original solution
#coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

def search_banpei(array, target, cnt):
    tmp = array[len(array)-1]
    array[len(array)-1] = target

    n = 0
    while array[n] != target:
        n += 1

    array[len(array)-1] = tmp
    if n < len(array) - 1 or target == tmp:
        cnt += 1
    return cnt        

def linear_search():  
    cnt = 0
    for t in T:
        for s in S:
            if t == s:
                cnt += 1
                break

def linear_banpei_search():
    cnt = 0
    for target in T:
        cnt = search_banpei(S, target, cnt)
    return cnt

cnt = linear_banpei_search()

print(cnt)



# Optimized solution
#coding:utf-8
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

def search_banpei(array, target, cnt):
    tmp = array[len(array)-1]
    array[len(array)-1] = target

    n = 0
    while array[n] != target:
        n += 1

    array[len(array)-1] = tmp
    if n < len(array) - 1 or target == tmp:
        cnt += 1
    return cnt        

def linear_search():  
    cnt = 0
    for t in T:
        for s in S:
            if t == s:
                cnt += 1
                break
    return cnt

def linear_banpei_search():
    cnt = 0
    for target in T:
        cnt = search_banpei(S, target, cnt)
    return cnt

cnt = linear_search()

print(cnt)
# Original solution
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

C = []
for s in S:
  for t in T:
    if s == t and not s in C: C.append(s)
print((len(C)))

# Optimized solution
n = int(eval(input()))
S = list(map(int, input().split()))
q = int(eval(input()))
T = list(map(int, input().split()))

C = 0
for t in T:
  for s in S:
    if s == t:
      C += 1
      break
print(C)