Problem:
 Score : 300 points    Problem Statement Snuke and Raccoon have a heap of N cards. The i -th card from the top has the integer a_i written on it.  They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.  Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y , respectively.
They would like to minimize |x-y| .
Find the minimum possible value of |x-y| .      Constraints  2 \leq N \leq 2 \times 10^5  -10^{9} \leq a_i \leq 10^{9}  a_i is an integer.         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_{N}       Output Print the answer.        Sample Input 1 6
1 2 3 4 5 6      Sample Output 1 1  If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10 , y=11 , and thus |x-y|=1 . This is the minimum possible value.       Sample Input 2 2
10 -10      Sample Output 2 20  Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10 , y=-10 , and thus |x-y|=20 .

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
b = sum(A)

ans = float("inf")
cum_sum = 0

for a in A[:-1]:
    cum_sum += a
    ans = min(ans, abs(2 * cum_sum - b))

print(ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
b=[]
sum=0
for a in A:
    sum+=a
    b.append(sum)

ans=float("inf")
for i in range(0,N-1):
    if ans>abs(b[-1]-b[i]*2):
        ans=abs(b[-1]-b[i]*2)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
ans = 1e12
work = 0
for i in range(N-1):
  work += A[i]
  ans = min(ans, abs(S - 2*work))

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a_sum=sum(a)
ans_list=[]
sunuke=a[0]
araiguma=a_sum-a[0]
for i in range (1,N):
    ans_list.append(abs(sunuke-araiguma))
    sunuke+=a[i]
    araiguma-=a[i]
print(min(ans_list))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

x = a[0]
y = sum(a[1:])
ans = abs(x-y)
for i in range(1, n-1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x-y))
print(ans)

Solution (Python):
from itertools import accumulate
N = int( input())
A = list( map( int, input().split()))
AA = list(accumulate(A))
ANS = abs( AA[0]*2 - AA[-1])
for i in range(N-1):
    K = abs( AA[i]*2 - AA[-1])
    ANS = min( K, ANS)
print(ANS)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return




dp = None


def main():
    N = int(input())
    A = li_input()
    C = []

    tmpsum = 0
    for a in A:
        tmpsum += a
        C.append(tmpsum)

    ans = 10**100

    for i in range(len(C) - 1):
        ans = min(ans, abs((C[-1] - C[i]) - C[i]))

    print(ans)


main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
count = 0
Near = 10 ** 15
for i in range(N-1):
    count = count + A[i]
    if abs(2 * Near - S) > abs(2 * count - S):
        Near = count
print(abs(2 * Near - S))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

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

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

print(res)

Solution (Python):
from itertools import accumulate as acc
input()
*s,S=list(acc(map(int,input().split())))
print(min(abs(S-2*x)for x in s))

Solution (Python):
from itertools import accumulate as acc
input()
s=list(acc(map(int,input().split())));S=s.pop()
print(min(abs(S-2*x)for x in s))

Solution (Python):
from itertools import accumulate as acc
input()
S=tuple(acc(map(int,input().split())))
print(min(abs(S[-1]-2*x)for x in S[:-1]))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x = []
y = []

s = 0
for i in a:
    s += i
    x.append(s)
s = 0
for i in a[::-1]:
    s += i
    y.append(s)
x = x[:-1]
y = y[:-1][::-1]

res = float('inf')
for (i,j) in zip(x,y):
    res = min(res, abs(i-j))
print(res)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
s1 = 0
s2 = sum(a)
for i in range(N-1):
    s1 += a[i]
    s2 -= a[i]
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)

Solution (Python):
a = int(input())

aa = list(map(int,input().split()))

for i in range(1,a):
  aa[i] += aa[i-1]
  
su = 10**20

for i in range(a-1):
  su = min(su,abs(aa[a-1]-2*aa[i]))
print(su)

Solution (Python):
N, = map(int, raw_input().split())
a = map(int, raw_input().split())
sl = [0]*N
sl[0] = a[0]
for i in range(N-1):
  sl[i+1] = sl[i]+a[i+1]
sr = [0]*N
sr[N-1] = a[N-1]
for i in range(N-1,0,-1):
  sr[i-1] = sr[i]+a[i-1]
r = abs(sl[0]-sr[1])
for i in range(1, N-1):
  r = min(r, abs(sl[i]-sr[i+1]))
print r

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

total = sum(A)

ans = float('inf')
nusuke = 0
for a in A[:-1]:
  nusuke += a
  ans = min(ans, abs(nusuke - (total - nusuke)))

print(ans)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

S = sum(A)
x = 0
ans = float('inf')
for i in range(N - 1):
    x += A[i]
    ans = min(ans, abs(S - x * 2))
print(ans)

Solution (Python):
N = int(input())

a = list(map(int,input().split()))

sum = 0
for a_i in a:
    sum+=a_i

min = abs(a[0]-(sum-a[0]))
x=a[0]
for a_i in a[1:-1]:
    x +=a_i
    if (min>abs(x-(sum-x))):
        min=abs(x-(sum-x))

print(min)

Solution (Python):

n = int(raw_input())
a = map(int, raw_input().split())

diff = None
min_diff = 999999999999999999
x = 0
y = sum(a)

for i in range(n - 1):
    x += a[i]
    y -= a[i]
    diff = abs(x - y)
    if diff < min_diff:
        min_diff = diff

print(min_diff)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

S = sum(A)
x = 0
ans = float('inf')
for i in range(N):
    x += A[i]
    if i < N - 1:
        ans = min(ans, abs(S - x * 2))
print(ans)

Solution (Python):
N = int(input())
A = [0] * N
sumA = 0
for i, x in enumerate(input().split()):
  sumA += int(x)
  A[i] = sumA
for i in range(N - 1):
  A[i] = abs(2 * A[i] - A[N - 1])
print(min(A[:-1]))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))

a_sum = sum(a)
x, ans = 0, 10**20

for i, v in enumerate(a):
    x += v
    if i < n-1:
        ans = min(ans, abs(a_sum-2*x))

print(ans)
exit(0)

Solution (Python):
n = int(input())
a = [int(v) for v in input().split()]

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

for i in range(1, n - 1):
    x += a[i]
    y -= a[i]
    diff = abs(x - y)
    ans = min(ans, diff)

print(ans)

Solution (Python):
n = int(input())
a = [int(v) for v in input().split()]

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

for i in range(1, n - 1):
    x += a[i]
    y -= a[i]
    diff = abs(x - y)
    if diff < ans:
        ans = diff

print(ans)

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]

sum_a = sum(a)

ai_sum = 0
for i in range(0, n-1):
    ai_sum += a[i]
    if i == 0:
        min_gap = abs(ai_sum * 2 - sum_a)
    if abs(ai_sum * 2 - sum_a) <= min_gap:
        min_gap = abs(ai_sum * 2 - sum_a)

print(min_gap)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
x = 0
ans = abs(sum_a - 2 * a[0])
for ai in a[:-1]:
    x += ai
    ans = min(ans, abs(sum_a - 2 * x))
print(ans)

Solution (Python):


def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    cumsum = []
    for i in range(n):
        if len(cumsum) == 0:
            cumsum.append(a_list[i])
        else:
            cumsum.append(cumsum[i - 1] + a_list[i])
    cumsum_reverce = []
    a_list.reverse()
    for i in range(n):
        if len(cumsum_reverce) == 0:
            cumsum_reverce.append(a_list[i])
        else:
            cumsum_reverce.append(cumsum_reverce[i - 1] + a_list[i])
    cumsum_reverce.reverse()

    ans = []
    for i in range(1, n):
        ans.append(abs(cumsum_reverce[i] - cumsum[i - 1]))
    print(min(ans))

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = tuple(map(int, input().split(" ")))

x, y = 0, sum(a)
min_num = 10000000000000
for a_i in a[:-1]:
	x += a_i
	y -= a_i
	tmp = abs(x-y)
	if tmp < min_num:
		min_num = tmp
print(min_num)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = a[:: -1]
pre = [0] * n
suf = [0] * n
pre[0] = a[0]
for i in range(1, n):
    pre[i] = pre[i - 1] + a[i]
suf[0] = b[0]
for i in range(1, n):
    suf[i] = suf[i - 1] + b[i]

ans = float("inf")
for i in range(n - 1):
    ans = min(ans, abs(pre[i] - suf[n - i - 2]))

print(ans)

Solution (Python):
from itertools import accumulate as ac
n=int(input())
l=list(ac(map(int,input().split())))
a=l[-1]
print(min(abs(a-2*i) for i in l[:-1]))

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())
aa = inpl()

S1 = 0
S2 = sum(aa)
ans = INF

for i,a in enumerate(aa):
	if i == N-1:
		break
	S1 += a
	S2 -= a
	ans = min(abs(S1-S2),ans)

print(ans)

Solution (Python):
def inpl(): return input().split()

n = int(input())
a = list(map(int, inpl()))
sa = sum(a)
b = [a[0]]
for i in range(1, n - 1):
    b.append(a[i] + b[i - 1])

ans = float('inf')
for x in b:
    ans = min(ans, abs(sa - 2 * x))
print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
cumsum = np.cumsum(a)
ans = []
for i in range(n-1):
    ans.append(abs(-cumsum[-1]+2*cumsum[i]))
print(min(ans))

Solution (Python):
import numpy
n = int(input())
a = [int(i) for i in input().split()]
a_sum = numpy.cumsum(a)
ans = []
for i in range(n-1):
    ans.append(abs(-a_sum[-1]+2*a_sum[i]))
print(min(ans))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

tot = sum(A)
half = tot / 2
res = 0
s, t = A[0], sum(A[1:])
min_v = abs(s - t)

for a in A[1:-1]:

    s += a
    tmp = abs(tot - 2 * s)
    if tmp < min_v:
        min_v = tmp

print(min_v)

Solution (Python):
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = True

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
list01 = [int(x) for x in arr_data[1]]

sumdata = sum(list01)

middledata = sumdata // 2

x = list01[0]
y = sumdata-x
temp=abs(x-y)

for i in range(1, n-1):

    x += list01[i]
    y = sumdata-x
    
    if temp>abs(x-y):
        
        temp=abs(x-y)
        
        
print(temp)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ans = sum(a) - 2*a[0]
abst = abs(ans)
for i in range(1,N-1):
    ans -=2*a[i]
    if abs(ans)<abst:
        abst = abs(ans)
print(abst)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]

a_cum = []
cumsum = 0


for i in a :
    cumsum += i
    a_cum.append(cumsum)

min_abs = 2*(10**9)

for i in range(0, len(a_cum) - 1) :
    x = a_cum[i]
    y = a_cum[len(a_cum) - 1] - x
    
    min_abs = min(abs(x - y), min_abs)
    
print(min_abs)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

snuke = a[0]
arai = sum(a) - snuke
ans = abs(arai-snuke)

for i in range(1,N-1):
    snuke += a[i]
    arai -= a[i]
    ans = min(ans, abs(arai-snuke))
    
print(ans)

Solution (Python):


N = int(input())
aN = list(map(int, input().split()))


sunuke = aN[0]
arai = sum(aN) - aN[0]
ans = abs(sunuke - arai)

for i in range(1, N-1):
    sunuke += aN[i]
    arai -= aN[i]
    ans = min(ans, abs(sunuke - arai))
print(ans)

Solution (Python):
n=int(input())

a=list(map(int,input().split()))

b = sum(a)

c=a[0]
d=b-c
mi=abs(c-d)

for i in range(1,n-1):
    c+=a[i]
    d-=a[i]
    if abs(c-d)<mi:
        mi=abs(c-d) 

print(mi)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
i=a[0]
j=sum(a)-i
ans=abs(i-j)
x=1
while (x+1)!=n:
    i+=a[x]
    j-=a[x]
    ans=min(ans,abs(i-j))
    x+=1
print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
cumSum = [0]
for i in range(N):
    cumSum.append(cumSum[i]+a[i])
def csum(l,r):
    return(cumSum[r]-cumSum[l-1])
def value(i):
    return(abs(csum(1,i)-csum(i+1,N)))
ans = value(1)
for i in range(1,N):
    ans = min(ans,value(i))
print(ans)

Solution (Python):


n = int(input())
A = list(map(int, input().split()))

_sum = [0]
for a in A:
    _sum.append(_sum[-1] + a)
del _sum[0]

ans = 10**100
for i in range(n-1):
    ans = min(ans, abs(_sum[i] - (_sum[-1] - _sum[i])))

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
t = 0
Min = float("inf")
for i in range(N - 1):
    t += a[i]
    s -= a[i]
    Min = min(Min, abs(s - t))

print(Min)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

summ = sum(A)
scores = []
i = 0
partsum = 0
while i <= N-2:
  partsum += A[i]
  scores.append(abs(summ-2*partsum))
  i += 1
print(min(scores))

Solution (Python):

N = int(input())
A = list(map(int, input().split()))

sum_A = sum(A)
temp = 2 * A[0] - sum_A
ans = abs(temp)

for i in range(1, N - 1):
    temp = temp + 2 * A[i]
    if abs(temp) < ans:
        ans = abs(temp)

print(ans)

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]

snuke = a[0]
total = sum(a)
arai = total - snuke

minimum = abs(snuke- arai)

for i in range(1,N-1):
    snuke = snuke + a[i]
    arai = arai - a[i]
    sub = abs(snuke-arai)
    if sub < minimum:
        minimum = sub

print(minimum)

Solution (Python):
import numpy

n = int(input())

arr = map(int,raw_input().split())

sumarr = numpy.cumsum(arr)
l = len(sumarr)
ans = float("inf")
for i in range(n-1):
	ans = min(ans,abs(sumarr[l-1]-2*sumarr[i]))

print ans

Solution (Python):
N = int(input())
input_list = [int(i) for i in input().split()]

index = 1
ruiseki_list = [0]*(N+1)
result = 10*9

if N == 2:
    print(abs(input_list[0]-input_list[1]))
else:
    for i in input_list:
        ruiseki_list[index] = ruiseki_list[index-1] + i
        index += 1

    mapped_list = map(lambda x: ruiseki_list[N]-x, ruiseki_list)
    result_list = [abs(a-b) for (a, b) in zip(ruiseki_list, mapped_list)]
    print(min(result_list[2:N]))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
x=[a[0]]
for i in range(1,n):
    x.append(x[-1]+a[i])
m=[]
for i in range(n-1):
    m.append(abs(x[-1]-2*x[i]))
print(min(m))

Solution (Python):
from itertools import accumulate as ac
N = int(input())
src = list(map(int,input().split()))
acum = list(ac(src))
ans = float('inf')
for i in range(N-1):
    ans = min(ans, abs(acum[i] - (acum[-1]-acum[i])))
print(ans)

Solution (Python):
N=int(input())
a = list(map(int,input().split()))

up = 0
down = sum(a)
result = abs(a[0]-(sum(a)-a[0]))

for i in a[:-1]:
    up += i
    down -= i
    if result > abs(up-down):
        result = abs(up-down)

print(result)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

top = 0
under = sum(A)
result = abs((A[0])-(sum(A)-A[0]))
for a in A[:-1]:
    top += a
    under -= a
    if result > abs(top - under):
        result = abs(top-under)
print(result)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
if N == 2:
    print(abs(a[1]-a[0]))
    exit()
S = sum(a)
m = float('inf')
memo = [0]*(N-1)
memo[0] = a[0]
for i in range(1,N-1):
    memo[i] = memo[i-1] + a[i]
for i in range(N-1):
    m = min(abs(S-memo[i]*2),m)

print(m)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
y = sum(A)
x=0
ans = []
for i in range(N-1):
    x +=A[i]
    y -= A[i]
    ans.append(abs(x-y))
ans.sort()
print(ans[0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

tmp = 0
sum_list = [0]
for i in range(n):
    tmp += a[i]
    sum_list.append(tmp)

diff = float('inf')
for i in range(1,n):
    diff = min(diff, abs(sum_list[-1]-2*sum_list[i]))

print(diff)

Solution (Python):
N = int(input())

A = list(map(int, input().split()))

rui = [0] * N

rui[0] = A[0]
for it in range(1, N):
    rui[it] = rui[it - 1] + A[it]

ans = 1145141919810
for i in range(0, N - 1):
    ans = min(abs(rui[i] - rui[N - 1] + rui[i]), ans)

print(ans)

Solution (Python):
def m():
    n = int(input())
    a = list(map(int, input().split()))
    b = a.copy()

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

    ans = 999999999999
    for j in range(n-1):
        ans = min(ans, abs(b[j] - a[j+1]))
    return ans
print(m())

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
tot = sum(A)
b = []
x=0
for i in range(N-1):
    x += A[i]
    b.append(abs(2*x-tot))
print(min(b))

Solution (Python):
import numpy
N = int(input())
cards = numpy.cumsum(list(map(int, input().split(' '))))
tmp = float('inf')
for i in range(N-1):
    diff = abs(cards[i] * 2 - cards[-1])
    tmp = min(tmp, diff)

print(tmp)

Solution (Python):





if __name__ == '__main__':
    from itertools import accumulate

    n = int(input())
    a = list(map(int, input().split()))

    
    
    
    summed_a = [0] + list(accumulate(a))
    total_a = sum(a)
    diff = float('inf')

    for i in range(1, n):
        diff = min(diff, abs(total_a - 2 * summed_a[i]))

    print(diff)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
a, b = l[0], sum(l)-l[0]
ans = abs(a-b)

for i in range(1, n-1):
  a += l[i]
  b -= l[i]
  if abs(a-b) < ans:
    ans = abs(a-b)

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

X, x = sum(a), a[0]
min_y = abs(X-2*x)

for i in range(1, n-1):
    x += a[i]
    if abs(X-2*x) < min_y:
        min_y = abs(X-2*x)

print(min_y)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
total=sum(a)
ans=[]
x=0
for i in range(n-1):
    x+=a[i]
    y=total-x
    ans.append(abs(x-y))
print(min(ans))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
S = [A[0]]+[0]*(N-1)
for i in range(1,N):
    S[i] = S[i-1] + A[i]
Ans = 10**10
for i in range(0,N-1):
    Ans = min(Ans,abs(S[N-1]-S[i]*2))
print(Ans)

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
sss = 0
for i in range(n):
    sss=sss + a[i]
ppp = 0
qqq = abs(sss - 2 * a[0])
for i in range(n-1):
    ppp=ppp + a[i]
    qo = abs(sss-2*ppp)
    if qqq > qo:
        qqq=qo
        
print(qqq)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

s=sum(a)
ans=abs(s-2*a[0])
s=s-2*a[0]

if n>3: 
 for i in range(1,n-1):
  ans=min(abs(s-2*a[i]),ans)

  s=s-2*a[i]
  
print(ans)

Solution (Python):
N = int(input())
src = list(map(int,input().split()))
s = sum(src)
ans = float('inf')
tmp = 0
for i in range(N-1):
    tmp += src[i]
    rem = s - tmp
    ans = min(ans, abs(tmp - rem))
print(ans)

Solution (Python):
N,x=int(input()),0
s=list(map(int,input().split()))
for j in s:
    x+=j
x=x-s[0]*2
ans=abs(x)
for k in range(1,N-1):
    x=x-s[k]*2
    ans=min(ans,abs(x))
print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ans = float('Inf')
total = sum(l)
now = 0
for i in range(n-1):
  now += l[i]
  if abs((total-now) - now) < ans:
    ans = abs((total-now) - now)

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
sumal=[0]*N
sumal[0]=a[0]
suma=sum(a)
for i in range(1,N-1):
    sumal[i]=sumal[i-1]+a[i]
minabs=10**10
sumal[N-1]=a[N-1]
for i in range(N):
    minabs=min(minabs,abs(suma-2*sumal[i]))
print(minabs)

Solution (Python):
def c_splitting_pile(N, A):
    
    
    total = sum(A)
    ans = float('inf')
    s = 0
    for i in range(N-1):
        s += A[i]
        ans = min(ans, abs(total - s * 2))
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_splitting_pile(N, A))

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
b = a[0]
m = abs(s - 2 * b)
for i in range(1, n - 1):
    b += a[i]
    m = min(m, abs(s - 2 * b))
print(m)

Solution (Python):
N = int(input())
a = [0 for i in range(N)]
S = 0
st = input().split()
for i in range(N):
    a[i] = int(st[i])
    S += a[i]
m = 4 * 10**14
T = 0
for i in range(0, N-1):
    T += a[i]
    M = abs(S-2*T)
    if M < m:
        m = M
print(m)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
x,y = a[0],sum(a)-a[0]
answer = abs(x-y)
for i in range(1,n-1):
	x += a[i]
	y -= a[i]
	if answer > abs(x-y):
		answer = abs(x-y)
print(answer)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

def solve():
    ans = float("inf")
    araiguma = sum(A)
    snuke = 0
    for A_i in A[0:-1]:
        snuke += A_i
        araiguma -= A_i
        score = abs(araiguma - snuke)
        if score < ans:
            ans = score
    print(ans)


solve()

Solution (Python):
n = int(input())
card = list(map(int,input().split()))
sum = [0]*(n+1)
for i in range(n):
  sum[i+1] = sum[i]+card[i]
miniS = pow(10,20)
for j in range(1,n):
  miniS = min(miniS,abs(sum[n]-2*sum[j]))
print(miniS)

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
ans = float('inf')
tmp = 0
for i in range(n):
    tmp += a[i]
    if i==n-1:
        continue
    ans = min(ans, abs(tmp-(total-tmp)))
print(int(ans))

Solution (Python):
import sys
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
if(n==2):
  mi=abs(a[0]-a[1])
else:
  mi=10**15
  s1=a[0]
  for i in range(1,len(a)-1):
    s1+=a[i]
    s2=s-s1
    
    mi=min([mi,abs(s1-s2)])
print(mi)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
v=sum(a)
ans=[]
x=0
for i in range(n-1):
    x+=a[i]
    ans.append(abs(2*x-v))
print(min(ans))

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

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

i=1

while i < n-1:
  x+=a[i]
  y-=a[i]
  m = min(abs(x - y),m)
  i+=1
print(m)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
s = sum(L)
r = N*10**9
p = 0
for i in range(N-1):
  p += L[i]
  r = min(r,abs(2*p-s))
print(r)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    solve(N,A)

def solve(N,A):
    ans = float("inf")

    
    ans = AC(N,A,ans)

    print(ans)

def TLE(N,A, ans):
    for i in range(1, N):
        snk = sum(A[:i])
        ari = sum(A[i:])

        ans = min(ans, abs(snk - ari))

    return ans

def AC(N,A,ans):
    cum_A = [None] * N
    cum_A[0] = A[0]
    for i in range(1, N):
        cum_A[i] = cum_A[i-1] + A[i]

    for i in range(N-1):
        snk = cum_A[i]
        ari = cum_A[-1] - snk

        ans = min(ans, abs(snk - ari))

    return ans

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
ans = float("inf")
x = 0

for i in range(n-1):
    x += a[i]
    ans = min(ans,abs(s-2*x))

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
total=sum(a)
ans=[]
x=0
for i in range(n-1):
    x+=a[i]
    ans.append(abs(2*x-total))
print(min(ans))

Solution (Python):
from itertools import accumulate
n = int(input())
cards = list(map(int, input().split()))
sums = list(accumulate(cards))
ans = float("inf")
for i in range(n-1):
    ans = min(ans, abs(sums[-1] - 2 * sums[i]))
print(ans)

Solution (Python):



N = int(input())
a = [0 for i in range(N)]
S = 0
st = input().split()
for i in range(N):
    a[i] = int(st[i])
    S += a[i]
m = 4 * 10**14
T = 0
for i in range(0, N-1):
    T += a[i]
    M = abs(S-2*T)
    if M < m:
        m = M
print(m)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
X=sum(a)

ans=[]
snuke=0

for i in range(n-1):
    snuke+=a[i]
    ans.append(abs(X-2*snuke))

print(min(ans))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
v=sum(a)
x=sum(a)
ans=[]
for i in range(n-1):
    x=x-a[i]
    ans.append(abs(v-2*x))
print(min(ans))

Solution (Python):
n = int(input())
xs = list(map(int, input().split()))

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

print(min([abs(xs[i] - (xs[-1] - xs[i])) for i in range(0, n-1)]))

Solution (Python):
N = int(input())
P = list(map(int,input().split()))
x = 0
y = sum(P)
ans = 10 ** 15
if N == 2:
    ans = abs(P[0] - P[1])
else:
    for i in range(N-1):
        x += P[i]
        y -= P[i]
        ans = min(ans, abs(x-y))
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split(" ")))
ans = []
sumval = sum(a)
if N == 2:
	print(abs(a[0]-a[1]))
	exit(0)
	
for i in range(N-2):
	a[i+1] += a[i]
	ans.append(abs(sumval-2*a[i+1]))

print(min(ans))

Solution (Python):


input()
xs = list(map(int, input().split()))

for i in range(len(xs) - 1):
    xs[i + 1] += xs[i]

res = 1 << 60
for i in range(len(xs) - 1):
    a = xs[i]
    b = xs[-1] - a
    if res > abs(a - b):
        res = abs(a - b)

print(res)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

l = a[0]
r = sum(a[1:])
ans = abs(l - r)

for i in range(1, N-1):
    now = a[i]
    l += now
    r -= now
    ans = min(ans, abs(l-r))
print(ans)

Solution (Python):
N = int(input())
cards = list(map(int,input().split()))

A_score = cards.pop(0)
B_score = cards.pop(len(cards)-1)
B_score += sum(cards)
min_diff_score = abs(A_score - B_score)

for card in cards:
    A_score += card
    B_score -= card
    now_diff_score = abs(A_score - B_score)
    if now_diff_score < min_diff_score:
        min_diff_score = now_diff_score

print(min_diff_score)

Solution (Python):

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = float("inf")

if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in range(0, len(cards)):
        res -= cards[i]
        res2 += cards[i]
        div = abs(res - res2)
        judge = div if div < judge and i != len(cards)-1 else judge

print(judge)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

arai = sum(a)-a[0]
sunuke = a[0]
ans = abs(sunuke-arai)
for i in a[1:-1]:
    sunuke += i
    arai -= i
    ans = min(abs(sunuke-arai), ans)

print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
x = sum(a)
t = sum(a)
difference = []
for i in range(n-1):
	x = x - a[i]
	difference.append(abs(t-2*x))
print(min(difference))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
x = sum(a)
y = 0
delta = []

for i in range(N-1):
    x = x - a[i]
    y = y + a[i]
    delta.append(abs(x-y))

print(min(delta))

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
X=0
Y=0
min=10**11
for i in range(N):
  X=X+a[i]

for j in range(N-1):
  Y=Y+a[j]
  if abs(X-2*Y) <= min:
   min=abs(X-2*Y)
print(min)

Solution (Python):
N = int(input())
a = [int(n) for n in input().split()]

x = 0
y = sum(a)
res = 1000000000000000

for i in range(N-1):
  x += a[i]
  y -= a[i]
  if res > abs(x-y):
    res = abs(x-y)
print(res)

Solution (Python):

"""
http://abc067.contest.atcoder.jp/tasks/arc078_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(cards):
    grand_total = sum(cards)
    
    snuke_total = cards[0]      
    min_diff = abs(grand_total - (snuke_total*2))
    for c in cards[1:-1]:       
        snuke_total += c
        min_diff = min(abs(min_diff), abs(grand_total - (snuke_total*2)))
    return min_diff


def main(args):
    N = int(input())
    cards = [int(x) for x in input().split()]
    result = solve(cards)
    print(result)



if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N = int(input())
num = [int(i) for i in input().split()]
ans = num[0]*2-sum(num)
ans_true = abs(ans)
for i in range(1, N-1):
    ans += num[i]*2
    if abs(ans) < ans_true:
        ans_true = abs(ans)
print(ans_true)

Solution (Python):
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 20


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    total = sum(a_list)

    dp1 = [0] * N
    dp1[0] = a_list[0]
    for i in range(1, N):
        dp1[i] = a_list[i] + dp1[i - 1]

    ans = INF
    for i in range(N - 1):
        ans = min(ans, abs(dp1[i] - (total - dp1[i])))
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
card = [int(i) for i in input().split(" ")]
 
all = 0
for i in card:
    all += i
 
a = card[0]
mab = abs(a - (all - a))
for i in range(1,len(card) - 1):
    a += card[i]
    if mab > abs(a - (all - a)):
    	mab = abs(a - (all - a))
print(mab)

Solution (Python):
def solve():  
    N = int(input())
    a = [int(x) for x in input().split(" ")]
    X = sum(a)
    sum_val = 0
    min_sum = 2 * 1e20

    for i in range(N-1):
        sum_val += a[i]
        y = X - sum_val
        min_sum = min(min_sum, abs(sum_val - y))

    print(min_sum)


solve()

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

b = sum(a)
c = a[0]
d = a[0]

for i in range(1, n-1):
    c += a[i]
    if abs(b-2*d) > abs(b-2*c):
        d = c

print(abs(b-2*d))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

s = sum(a)
x = a[0]

ans = abs(x - (s - x))
for aa in a[1:N-1]:
    x += aa
    ans = min(ans, abs(x - (s - x)))

print(ans)

Solution (Python):
N= int(input())

A = list(map(int, input().split()))

x = 0
sum = sum(A)
ans = 10**25

for i in range(N-1):
    x += A[i]
    y = sum - x
    ans = min(ans,abs(x-y))

print(ans)

Solution (Python):
def main():
    n = input()
    a_list = [int(i) for i in input().split()]
    sumv = sum(a_list)
    minv, tmp = 10**9 * 2, 0
    for a in a_list[:-1]:
        tmp += a
        if abs(sumv-2*tmp) < minv: minv = abs(sumv-2*tmp)
    print(minv)


if __name__ == "__main__":
    main()