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):
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    s = sum(a)
    x = 0
    m = float('inf')

    for i in a[:-1]:
        x += i
        y = s - x
        m = min(m, abs(x - y))
    
    return m

main()

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

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

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

z=sum(a)

sum=0
min=10**10
for i in range(n-1):
    sum+=a[i]
    x=sum
    y=z-x
    if abs(x-y)<min:
        min=abs(x-y)
print(min)

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

X = list(map(int, input().split()))
ans = 1000000000000000000
before = 0
after = sum(X)
X = X[:-1]
for i in X:
    before += i
    after -= i
    num = abs(before - after)
    ans  = min(ans, num)
print(ans)

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

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

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
accum = [0 for i in range(N+10)]
L_sum = sum(L)
ans = 10**100
for i in range(len(L)):
    accum[i+1] = accum[i] + L[i]
for i in range(1,len(L)):
  
    ans = min(ans,abs(2*accum[i]-L_sum))
print(ans)

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

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

s = a[0]
t = sum(a) - a[0]

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

print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
sumA=sum(A)
T=[0]*n
for i in range(1,n):
  T[i]=T[i-1]+A[i-1]
print(min(abs(sumA-2*T[i]) for i in range(1,n)))

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
res = float("inf")
arai = sum(a)
sunuke = 0
ans = sum([abs(a[i]) for i in range(n)])
if n == 2:
    print(abs(a[0] - a[1]))
    exit()
for i in range(n-1):
    sunuke += a[i]
    arai -= a[i]
    ans = min(ans, abs(arai-sunuke))
print(ans)

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

A_total[0] = A[0]

for i in range(1,len(A)):
    A_total[i] = A_total[i-1] + A[i]

min_num = float('inf')

for i in range(len(A_total[:-1])):
    snuke = A_total[i]
    bear = A_total[-1] - A_total[i]
    tmp = abs(snuke-bear)
    if min_num > tmp:
        min_num = tmp

print(min_num)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
s = sum(A)
ans = 10**20
x = 0
for i in range(N-1):
    x += A[i]
    y = s - x
    tmp = abs(x-y)
    if tmp < ans: ans = tmp
print(ans)

Solution (Python):

from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np


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

ans = 10**100
res = np.cumsum(a)

print(min([abs(res[-1]-res[i]-res[i]) for i in range(len(res)-1)]))

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

X = sum(a)
b = []
c = 0
for i in a[:-1]:
    c += i
    b.append(abs(X-2*c))
print(min(b))

Solution (Python):
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()
snuke = sum(a[:-1])
arai = a[-1]
ans = abs(snuke-arai)
for i in range(2, n):
    debug(a[-i])
    snuke -= a[-i]
    arai += a[-i]
    ans = min(abs(snuke - arai), ans)
    
print(ans)

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

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

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

print(ans)

Solution (Python):
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))

Solution (Python):
def solve(N, As):
    d = 0
    s = sum(As)
    m = 10 ** 15
    for a in As[:N - 1]:
        d += a
        m = min(m, abs(d - (s - d)))
    return abs(m)


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

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

X = sum(a)
b = [a[0]]
for i in range(1, N - 1):
    b.append(b[i-1] + a[i])

ans = []
for i in range(0, N - 1):
    ans.append(abs(X - 2*b[i]))

print(min(ans))

Solution (Python):
n = int(input())
*a, = map(int, input().split())
Table = [0, sum(a)]
ans = float("inf")

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

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

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

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

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

tmp = 0
ans = 10 ** 10
for i in range(n - 1):
    tmp += A[i]
    ans = min(ans, abs(tmp -(sumA - tmp)))
print(ans)

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

subtotals = [cards[0]]
for i in range(1, N):
    subtotals.append(subtotals[i - 1] + cards[i])

ans = 0
for i in range(N - 1):
    diff = abs(subtotals[-1] - 2*subtotals[i])
    ans = diff if i == 0 else min(ans, diff)

print(ans)

Solution (Python):
from itertools import accumulate
N = int(input())
a = list(map(int, input().split()))

acc = list(accumulate(a))

ans = 10**18
for i in range(N-1):
    ans = min(ans, abs((acc[i])-(acc[-1]-acc[i])))
print(ans)

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
x = 0
s = sum(A)
ab = -1
for i in range(n-1):
    a = A[i]
    x += a
    if ab == -1:
        ab = abs(s - 2*x)
    else:
        ab = min(ab, abs(s - 2*x))
print(ab)

Solution (Python):
import numpy as np

N = int(input())
l = list(map(int, input().split()))
nl = np.array(l)
X = nl.sum()
a = []
x = 0
for i in range(N-1):
    x = x + nl[i]
    a.append(abs(2 * x - X))
print(min(a))

Solution (Python):
import numpy as np
n=int(input())
a = [int(i) for i in input().split()]
ala = sum(a)
tmp = 0
ans = np.array([9999999999]*n)

for i in range(n-1):
 tmp += a[i]
 ala = ala - a[i]
 ans[i] = abs(tmp-ala)
print (min(ans))

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

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]
    score = abs(x-y)
    if score < ans:
        ans = score

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

A_r = A[::-1]

cumsum_A = np.cumsum(A)
cumsum_A_r = np.cumsum(A_r)

x = [abs(a - a_r) for (a, a_r) in zip(cumsum_A[:-1], cumsum_A_r[-2::-1])]
print(min(x))

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

suma=sum(a)
minans=abs(2*a[0]-suma)


mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)

Solution (Python):
N = int(input())
arr = list(map(int,input().split()))
mins = 10**10
csum = [0 for _ in range(N)]
csum[0] = arr[0]
for i in range(1,N):
    csum[i] = csum[i-1] + arr[i]    
for i in range(N-1):
    cards = abs(csum[N-1]-2*csum[i])
    if cards < mins:
        mins = cards
print(mins)

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

l=[0]
def ruiseki(a):
    for i in range(n):
        l.append(l[i]+a[i])
    del l[0]

ans=100000000000000
ruiseki(a)
x=0
y=0

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

print(ans)

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

sunuke = 0
arai = sum(a)
ans = float('inf')

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

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
r = [0]*n
ans = float('Inf')

for i in range(n):
  if i == 0:
    r[i] = a[i]
  else:
    r[i] = r[i-1] + a[i]
    
for i in range(n-1):
  ans = min(ans, abs((r[-1] - r[i]) - r[i]))

print(ans)

Solution (Python):
def abc067_c():
    n = int(input())
    a = list(map(int, input().split()))
    x = a[0]
    y = sum(a[1:])
    del a[0]
    del a[-1]
    diff = abs(x - y)
    for v in a:
        x += v
        y -= v
        if abs(x - y) < diff:
            diff = abs(x - y)
    print(diff)


abc067_c()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
    
A = a[0]
B = sum(a[1:])

min = abs(A - B)

for i in range(N-2):
    A += a[i+1]
    B -= a[i+1]

    if min > abs(A - B):
        min = abs(A - B)


print(min)

Solution (Python):

n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n-1):
    mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i])))
print(int(mm))

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

x = 0
y = sum(a)
cand = []
for e in a[:N-1]:
    x += e
    y -= e
    cand.append(abs(x-y))
print(min(cand))

Solution (Python):
n = int(input().strip())
a = list(map(int, input().strip().split()))
x, y = a[0], sum(a[1:])
minxy = abs(x-y)

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

print(minxy)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
A = sum(a[:n-1])-a[n-1]
c = n*(10**9)
c = min(c,abs(A))
if n == 2:
    print(abs(a[0]-a[1]))
else:
    for i in range(1,n-2):
        A=A-2*a[n-1-i]
        c = min(c,abs(A))
    print(c)

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

Solution (Python):
def main():
    _ = int(input())
    aa = list(map(int, input().split()))
    x = aa[0]
    y = sum(aa[1:])
    res = abs(x - y)
    for a in aa[1:-1]:
        x += a
        y -= a
        res = min(res, abs(x - y))
    print(res)


if __name__ == '__main__':
    main()

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

total = sum(A)

result = 10**100
x = 0
for a in A[:-1]:
    x += a
    r = abs(total - x - x)
    result = min(result, r)

print(result)

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

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

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()))
S=sum(A)
B=[A[0]]
for j in range(1,N):
    B.append(B[j-1]+A[j])


ans=10000000000
for i in range(N-1):
    ans=min(abs((S-B[i])-B[i]),ans)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
ans = float('inf')
for a in A[:-1]:
    S -= 2 * a
    if abs(S) < ans:
        ans = abs(S)
print(ans)

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

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

ans = float('inf')

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

print(ans)

Solution (Python):
N=int(input())
number=list(map(int,input().split()))
Sum=sum(number)
number_sum=[0]*N
number_sum[0]=number[0]
result=[0]*(N-1)
for i in range(1,N):
  number_sum[i]=number_sum[i-1]+number[i]
result[0]=abs(number_sum[0]*2-Sum)
for i in range(1,N-1):
  result[i]=abs(((number_sum[i])*2-Sum))

print(min(result))

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

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

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

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

print(diff)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sum=[0,]*n
sum[0]=a[0]
min=5000000000
for i in range(1,n):
    sum[i]=a[i]+sum[i-1]
fin=sum[n-1]
sub=[0,]*n
for i in range(0,n):
    sub[i]=fin-sum[i]
for i in range(0,n-1):
    if abs(sub[i]-sum[i]) < min:
        min = abs(sub[i]-sum[i])
print(str(min))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
tmp=[]
all_sum=sum(a)
tmp_sum=0
tmp_sum2=all_sum
for i in range(n-1):
    tmp_sum+=a[i]
    tmp_sum2-=a[i]
    tmp.append(abs(tmp_sum-tmp_sum2))
print(min(tmp))

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

Solution (Python):
import itertools
import math

N = int(input().strip())
al = list(map(int,input().strip().split(" ")))

pos = 1 

diff = 1000000000
asum = sum(al)
tmp_sum = 0

diff = []
for a in al[:-1]:
    tmp_sum += a
    diff.append(abs(asum - tmp_sum * 2))

print(min(diff))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
tmp=[]
all_sum=sum(a)
tmp_sum=0
tmp_sum2=all_sum
for i in range(n-1):
    tmp_sum+=a[i]
    tmp_sum2-=a[i]
    tmp.append(abs(tmp_sum-tmp_sum2))
print(min(tmp))

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]+[0]
sumsub = A[0]
sumall = sum(A)
ans = abs(2*sumsub-sumall)
for i in range(1, N-1):
    sumsub += A[i]
    ans = min(ans, abs(2*sumsub-sumall))
print(ans)

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

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

print(score)

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

Solution (Python):
n = int(input())
a = input().split()
a = [int(m) for m in a]
xyli = []
for i in range(n - 1):
    if i == 0:
        snu = a[i]
        ara = sum(a) - a[i]
        xyli.append(abs(snu - ara))
    else:
        snu += a[i]
        ara -= a[i]
        xyli.append(abs(snu - ara))
print(min(xyli))

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
a1_list = a_list
res_list =[]
a_score = 0
s_score = 0
for i in range(n):
    a_score += a_list[i]    
for i in a1_list:
    a_score -= i
    s_score += i
    res = abs(s_score - a_score)
    res_list.append(res)
del res_list[n-1]
print(min(res_list))

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

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

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

sum = 0
for a in A:
    sum += a
x = A[0]
y = sum - A[0]
min_num = abs(x-y)

for i in range(1, len(A)-1):
    x = x + A[i]
    y = y - A[i]
    n = abs(x-y)
    if n < min_num:
        min_num = n
print(min_num)

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

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

r = []

ruiseki = 0
for val in a:
    ruiseki += val
    r.append(ruiseki)

ans = 999999999999
for i in range(N-1):
    if ans > abs(r[-1] - r[i] - r[i]):
        ans = abs(r[-1] - r[i] - r[i])
print(ans)

Solution (Python):

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

a_sum = [0] * N
tmp = 0
for i, ai in enumerate(a):
    tmp += ai
    a_sum[i] = tmp

def diff(A, B): return A - B if A > B else B - A
    
ans = 0
ans_diff = diff(a_sum[0], a_sum[-1] - a_sum[0])
for tmp in range(1, N - 1):
    tmp_diff = diff(a_sum[tmp], a_sum[-1] - a_sum[tmp])
    if tmp_diff < ans_diff: ans, ans_diff = (tmp, tmp_diff)

print(ans_diff)

Solution (Python):
a = int(input())
ar = list(map(int,input().split(" ")))
count = 0
mc = 0
for r in ar:
    mc += r
br = []
for i in range(a-1):
    count += ar[i]
    br.append(abs((mc - count) - count))
print(min(br))

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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans > abs(p-q) :
            ans = abs(p-q)
        
print(ans)

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

Solution (Python):


import sys

input = sys.stdin.readline
INF = float('inf')


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


N = int(input())
A = inpl()
B = [0]
for a in A:
    B.append(B[-1] + a)
del B[0]

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

print(ans)

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

Solution (Python):
def 解():
    iN = int(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))
解()

Solution (Python):
def 解():
    iN = int(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)
解()

Solution (Python):

def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    
    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)
解()

Solution (Python):

def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]

    iD = sum(aA)
    iF = 0
    iB = iD
    minDiff =  10**9 * 2
    for a in aA[:-1] :
        iF += a
        iB -= a
        thisDiff = abs(iF - iB)
        minDiff = min(minDiff , thisDiff)
    print(minDiff)
解()

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = -1
sum_ = sum(a)
sunuke = 0
for i in range(n-1):
    sum_ -= a[i]
    sunuke += a[i]
    tmp = abs(sum_ - sunuke)
    if ans == -1:
        ans = tmp
    if ans > tmp:
        ans = tmp
print(ans)

Solution (Python):
N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12
after = sum(L)
before = 0
for i in range(N-1):
    before += L[i]
    after -= L[i]
    if abs(before -after) < tmp:
        tmp = abs(before -after)
print(tmp)

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

x, y = 0, sum(a)
m = 1e14

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

print(m)

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

X = sum(a)
x = 0
ans = 10**100

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

Solution (Python):

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

sunuke_l = []
sunuke = 0
arai_l = []
arai = 0
all_sum = sum(a)
diff_l = []
for i in range(N-1):
    sunuke = sunuke + a[i]
    arai = all_sum - sunuke
    diff_l.append(abs(sunuke - arai))

print(min(diff_l))

Solution (Python):
n, aa = input(), list(map(int, input().split()))
s = sum(aa)
m = s / 2
i = 0
min = float("inf")
ans = 0
aa.pop()
for a in aa:
    s -= a
    i += a  
    dif = abs(s - m)
    if dif < min:
        min = dif
        ans = abs(s-i)
print(ans)

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

x = 0
y = 0
min = 1e14
for i in range(n):
    y += a[i]
for i in range(n-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < min:
        min = abs(x-y)
print(min)

Solution (Python):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = int(2e+9)
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans = min(ans, abs(X-2*x))
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    x = 0
    for i in range(N-1):
        x += l[i]
        ans.append(abs(X-2*x))
    print(min(ans))
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print(min(ans))
if __name__ == '__main__':
    main()

Solution (Python):

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

sl = sum(a[:1])
sr = sum(a[1:])

ans = int(1e9)
for i in range(1, N-1):
    sl += a[i]
    sr -= a[i]
    ans = min(ans, abs(sl - sr))

if N == 2:
    ans = abs(a[0] - a[1])
print(ans)

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
Sunuke = A[0]
Rac = sum(A[1:])
minPoint = abs(Sunuke-Rac)
for i in range(1, N-1):
    Sunuke += A[i]
    Rac -= A[i]
    minPoint = min(minPoint, abs(Sunuke-Rac))
print(minPoint)

Solution (Python):
n = int(input())
listA= list(map(int, input().split()))
listSum=[]

sum =0
index=0
while index < len(listA):
    if index==0:
        sum+=listA[index]
        listSum.append(sum)
    else:
        sum = listSum[index-1]+listA[index]
        listSum.append(sum)
    index+=1

allSum = listSum[len(listSum)-1]
index2=0
minDelta =2*(10**9)
while index2 < len(listSum)-1:
    if max(allSum - listSum[index2], listSum[index2]) - min(allSum - listSum[index2], listSum[index2]) < minDelta:
        minDelta = max(allSum - listSum[index2], listSum[index2]) - min(allSum - listSum[index2], listSum[index2]) 
    index2+=1

print(minDelta)

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

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

del_A = [0]

for i in range(N):
    del_A.append(del_A[i] + A[i])

ans = 10**10

for i in range(1,N):
    x = del_A[i]
    y = del_A[-1] - x

    tmp = abs(x-y)

    ans = min(tmp,ans)
print(ans)

Solution (Python):
N = int(input())
src = list(map(int,input().split()))
cums = [0]
for a in src:
    cums.append(cums[-1] + a)

ans = float('inf')
for i in range(1,N):
    l = cums[i]
    r = cums[-1] - cums[i]
    ans = min(ans, abs(l-r))
print(ans)

Solution (Python):

"""
Created on Sat Sep 22 16:00:08 2018
ABC067C
@author: maezawa
"""
n = int(input())
a = list(map(int, input().split()))

total = sum(a)
cum = a[0]
dif = abs(total - 2*cum)

for i in range(1,n-1):
    cum += a[i]
    if abs(total-2*cum) < dif:
        dif = abs(total-2*cum)
        
print(dif)

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A_sum = sum(A)
deltas = [A_sum]
res = []
for i in range(N-1):
    deltas.append(deltas[-1] - 2*A[i])
    res.append(abs(deltas[-1]))
print(min(res))

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

    ans = INF
    total = sum(A)
    now = 0
    for i in range(N - 1):
        now += A[i]
        ans = min(ans, abs((total - now) - now))
    print(ans)


if __name__ == '__main__':
    main()

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

a_sum = sum(a_list)
min_num = float("inf")
r = []

for i in range(1, N):
    if len(r) == 0:
        r.append(a_list[0])
    else:
        r.append(r[i-2] + a_list[i-1])

    x = r[i-1]
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)

Solution (Python):

N=int(input())
a=list(map(int,input().split()))
x=a[0]
y=sum(a)-x
ans=abs(x-y)
for i in range(N-2):
    x+=a[i+1]
    y-=a[i+1]
    if ans>abs(x-y):
        ans=abs(x-y)
print(ans)

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

sunuke = 0
araiguma = sum(a)
for i in range(N-1):
  sunuke += a[i]
  araiguma -= a[i]
  if(i==0):
     result = abs(sunuke-araiguma)
  else:
     result = min(result, abs(sunuke-araiguma))

print(result)

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, = map(int, raw_input().split())
a = map(int, raw_input().split())
x = a[0]
y = sum(a) - a[0]
r = abs(x-y)
for ai in a[1:N-1]:
  x += ai
  y -= ai
  r = min(r, abs(x-y))
print r

Solution (Python):
N = int(input())
a = [int(ai) for ai in input().split()]
a_sum = sum(a)
best = 10**12
tmp = 0
for ai in a[:-1]:
    tmp += ai
    best = min(best, abs(tmp - (a_sum - tmp)))
print(best)

Solution (Python):
N, = map(int, raw_input().split())
a = map(int, raw_input().split())
x = a[0]
y = sum(a) - a[0]
r = abs(x-y)
for ai in a[1:N-1]:
  x += ai
  y -= ai
  r = min(r, abs(x-y))
print r

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
result=10000000000
total=0
suma=sum(a)
for i in range(n-1):
    total +=a[i]
    sa = abs(suma - 2*total)
    if sa <result:
        result=sa
print(result)