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.



Sample input:
6
1 2 3 4 5 6


Sample output:
1

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

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

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

    # See:
    # https://atcoder.jp/img/arc078/editorial.pdf
    # total_a = sum(a)
    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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
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)
#  print(ans)
  s=s-2*a[i]
  
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def c_splitting_pile(N, A):
    # Aの要素の総和をX、カードの山の先頭i枚の総和をxとすると、
    # |y-x|=|X-2x|である。各iについてこの値を計算すればよい
    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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env 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))

Submission status: Accepted

Solution code:
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
    #print(s1,s2)
    mi=min([mi,abs(s1-s2)])
print(mi)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

    solve(N,A)

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

    # ans = TLE(N,A,ans)
    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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)]))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:


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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
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]      #  すぬけ君は最低でも1枚は引く必要がある
    min_diff = abs(grand_total - (snuke_total*2))
    for c in cards[1:-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:])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def solve():  # 068C - Splitting Pile
    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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
x=a[0]
y=0
for i in range(1,N):
  y+=a[i]
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-       

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

l, r = a[0], sum(a[1:])
min_diff = abs(l-r)
for i in range(1,n-1):
    l += a[i]
    r -= a[i]
    diff = abs(l-r)
    min_diff = min(min_diff,diff)
print(min_diff)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
x=0
y=sum(a)
b=[]
for p in range(N-1):
    x=x+a[p]
    y=y-a[p]
    b.append(abs(x-y))
print(min(b))

Submission status: Accepted

Solution code:
def Q3(x):
    N = x[0][0]
    lst = x[1][:]
    s = lst[0]
    allsum = sum(lst)
    minimum = abs(allsum - s * 2)
    
    for k in range(1, N - 1):
        s += lst[k]
        a = abs(allsum - s * 2)
        minimum = min(minimum, a)
    return minimum

l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
n = [l,m]
print(Q3(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

'''math
total=x+y
y=total-x
x-y=x-(total-x)
   =2x-total
|x-y|=|2x-total|
'''

total = sum(a)
x = a[0]
answer = abs(x*2-total)
for i in range(1,N-1):
    x += a[i]
    answer = min(answer, abs(x*2-total))

print answer

Submission status: Accepted

Solution code:
def splitting_pile_2():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	total_sum = sum(nums)
	left_sum = nums[0]
	ans = abs(total_sum-left_sum*2)

	for i in range(1, n-1):
		left_sum = left_sum + nums[i]
		ans = min(ans, abs(total_sum-left_sum*2))
	print ans


if __name__ == "__main__":
	splitting_pile_2()

Submission status: Accepted

Solution code:
from math import * 
n=int(input())
l=[int(x) for x in input().split()]
summ=sum(l)
sum1=0
ans=10**30
for i in range(n-1):
    sum1+=l[i]
    ans=min(ans,abs(summ-2*sum1))
print(ans)

Submission status: Accepted

Solution code:
m = int(input())
n = list(map(int, input().split()))
sunuke = 0
araiguma = sum(n)
 
min = 10000000000
for i in range(m - 1):
    araiguma -= n[i]
    sunuke += n[i]
    #print(abs(sunuke - araiguma))
    if min > abs(sunuke - araiguma):
        min = abs(sunuke - araiguma)
print(min)

Submission status: Accepted

Solution code:
a = input()

card_list = list(map((int),input().split(' ')))

sum_card = sum(card_list)

score = []
sunuke = 0

for i in range(int(a)-1):
    
    sunuke += card_list[i]
    score.append(abs(sum_card-2*sunuke))

print(min(score))

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
X=sum(a)
ans=[]
Y=0
for i in range(N-1):
#    A=abs(X-2*sum(a[0:i]))
    Y=Y+a[i]
    B=abs(X-2*Y)
    ans.append(B)
ans1=min(ans)
print(ans1)

Submission status: Accepted

Solution code:
N =int(input())
a = list(map(int, input().split()))
k_p = a[0]
a_p = sum(a[1:])
m = abs(k_p - a_p)
for i in range(1, N-1):
    k_p += a[i]
    a_p -= a[i]
    if abs(k_p - a_p) < m:
        m = abs(k_p - a_p)
print(m)

Submission status: Accepted

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

sum_a = sum(a)

minv = abs(2*a[0] - sum_a)
cc = a[0]

for i in range(1, N-1):
    
    cc += a[i]
    minv = min(abs(2*cc - sum_a), minv)
        
print(minv)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
n = int(input())
a =list(map(int, input().split()))

N = sum(a)
r = float('inf')
x = 0
 
for i in range(n-1):
    x += a[i]
    y = N - x
    if r > abs(x -y):
        r = abs(x -y)
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))

snk = 0
arg = 0

for i in range(0, N):
	arg += a[i]

s = 100000000000000

for i in range(0, N - 1):
	snk += a[i]
	arg -= a[i]
	ss = snk - arg
	if ss < 0:
		ss *= -1

	if s > ss:
		s = ss

print(s)

Submission status: Accepted

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

su = sum(a)
diff = 1e10
cc = 0

for i in range(len(a)-1):
    cc += a[i]
    diff = min(diff, abs(cc-(su-cc))) # x-y
print(diff)

Submission status: Accepted

Solution code:
import math as ma
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
A = 0
diff = 9999999999
for i in range(N-1):
    A += a[i]
    if diff > (ma.fabs(2*A - s)):
        diff = ma.fabs(2*A -s)
print(int(diff))

Submission status: Accepted

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

S = sum(A) - 2 * A[0]
res = abs(S)
flag = 1
while res != 0 and flag < N - 2:
    S -= 2 * A[flag]
    if res > abs(S):
        res = abs(S)
    flag += 1
print(res)

Submission status: Accepted

Solution code:
N= int(raw_input())
A = list(map(int, raw_input().split()))
start_diff = abs(sum(A[1:]) - A[0])
diff = sum(A[1:]) - A[0]
for index in xrange(1,len(A)-1):
        diff -= A[index] * 2
	if abs(diff) < start_diff:
		start_diff = abs(diff)

print start_diff

Submission status: Accepted

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

diff = []
former = a[0]
latter = sum(a[1:])
diff = [abs(a[0]-sum(a[1:]))]
for n in range(1,N-1):
    former += a[n]
    latter -= a[n]
    diff.append(abs(former-latter))
print(min(diff))

Submission status: Accepted

Solution code:
#! python3

N = int(input())
a = [int(x) for x in input().split(' ')]
S = sum(a)
diff = abs(S - 2*a[0])
acc = a[0]
for x in a[1:-1]:
    acc += x
    if abs(S - 2*acc) < diff:
        diff = abs(S-2*acc)
print(diff)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
cards = list(map(int, input().split()))
ans = float("inf")
y = sum(cards)
x = 0
L = []

for card in cards:
    x += card
    y -= card
    L.append(abs(x-y))
    
del L[N-1]

print(min(L))

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in a[1:-1]:
    sunuke += i
    diff = min(diff, abs(s - 2 * sunuke))

print(diff)

Submission status: Accepted

Solution code:
def mainC():
    #import numpy as np
    N = int(input())
    a = list(map(int, input().split()))
    s = sum(a)
    d2 = a[0]
    m = abs(s-2*d2)
    for i in range(1, N-1):
        d2 += a[i]
        m = min( m, abs(s-2*d2) )
    print( m )

mainC()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    ans = float("inf")
    n = int(input())
    a = list(map(int, input().split()))

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

    for i in range(0,n-1):
        ans = min(ans, abs(2*b[i]-b[n-1]))
    print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=[int(x) for x in input().split()]
l=0
r=sum(a)
d=[]
for i in range (N-1):
 l +=a[i]
 r -=a[i]
 d.append(abs(l-r))
print (min(d))

Submission status: Accepted

Solution code:
N = int(input())
l = [0] * N
l = list(map(int, input().split()))
sum = 0
a = [0] * N
for i in range(N):
    sum += l[i]
x = 0
result = 1145141919810931931
for i in range(N):
    x += l[i]
    if i + 1 < N:
        result = min((result, abs(sum - 2 * x)))
print(result)

Submission status: Accepted

Solution code:
n = int(raw_input())
l = map(int, raw_input().split())
s = sum(l)
t = 0
d = 10**15
for i in range(n-1):
    t += l[i]
    d = min(d, abs(t - (s-t)))
print d

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
sm = sum(a)
x = 0
ans = 10 ** 80
for i in range(N-1):
    x += a[i]
    y = sm - x
    ans = min(ans, abs(x - y))
print(ans)

Submission status: Accepted

Solution code:
m = int(input())
n = list(map(int, input().split()))
sunuke = 0
araiguma = sum(n)

min = 10000000000
for i in range(m - 1):
    araiguma -= n[i]
    sunuke += n[i]
    #print(abs(sunuke - araiguma))
    if min > abs(sunuke - araiguma):
        min = abs(sunuke - araiguma)
print(min)

Submission status: Accepted

Solution code:
def solution(a):
    A = a[0]
    B = sum(a) - a[0]
    Min = abs(A - B)
    for i in xrange(1, len(a)-1):
        A += a[i]
        B -= a[i]
        if Min > abs(A- B):
            Min = abs(A - B)
    print Min
import math
N = int(raw_input())
a = map( int, raw_input().split())
solution(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

s = 0
a = sum(l)
ans = float('inf')

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import re
import sys

n = int(raw_input())
a = map(int, re.split('\s', raw_input()))

ans = 10000000001

all = sum(a)
tmp = 0

if (n == 2):
        print abs(a[0] - a[1])
        sys.exit()

for i in range(0, n-2):
        tmp += a[i]
        hoge = abs(all - 2 * tmp)
        if (ans > hoge):
                ans = hoge

print ans

Submission status: Accepted

Solution code:
n = raw_input()
a = raw_input().split(' ')
a = map(int, a)
s = 0
sunuke = a[0]
arai = a[len(a)-1]
for i in a:
	s = s + i
m = abs(sunuke - (s - sunuke))
 
for i in range(1,len(a)-2):
	sunuke = sunuke + a[i]
	arai = s - sunuke
	if abs(arai-sunuke) < m:
		m = abs(arai-sunuke)
 
 
print m

Submission status: Accepted

Solution code:
n = int(input())
a = tuple(map(int, input().split()))
s = sum(a)
ans = 10**10
sunuke = 0
for i in range(n - 1):
    sunuke += a[i]
    ans = min(ans, abs(2 * sunuke - s))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
l = [int(i) for i in input().split()]
#print(len(l))
A = []
x = 0
X = sum(l)
ans = 100000000000000

for i in range(N):
	x += l[i]
	if i + 1 < N:
		ans = min(ans,int(math.fabs(X-2*x)))


 
	
#print(int(sum/2))
#print(x,y)
print(ans)

Submission status: Accepted

Solution code:
p = lambda  x: x#print(x)

# スペース区切りの整数の入力
N = int(input())

l = [int(i) for i in input().split()]

# X = sum(l)
# x = 0
# ans = 1000000000000000000
# 
# for i in range(N-1):
# 	x += l[i]
# 	ans = min(ans, abs(X-2*x))
# 
# print(ans)

p(N)
p(l)

s = 0
a = sum(l)
ans = float('inf') 

p("s=" + str(s))
p("ans=" + str(ans))
p("a=" + str(a))
p("abs(s - a)=" + str(abs(s - a)))


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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = map(int, raw_input().split())
x = a[0]
y = sum(a) - a[0]
min = abs(x - y)
for i in range (1,N-1):
    y -= a[i]
    x += a[i]
    dummy = abs(x - y)
    if min > dummy:
        min = dummy
print min

Submission status: Accepted

Solution code:
N=map(int,input().split())
a=[int(x) for x in input().split()]
x=a[0]
y=sum(a[1:])
min=abs(x-y)
tmpmin=min
for i in range(1,len(a)-1):
    x+=a[i]
    y-=a[i]
    tmpmin=abs(x-y)
    if tmpmin<min:
        min=tmpmin
print(min)

Submission status: Accepted

Solution code:
def sa(_a,_b):
    a = max(_a,_b)
    b = min(_a,_b)
    return a-b

n = int(input())
l = list(map(int,input().split()))
m = sum(l)
a = l[0]
b = m - a
ans = sa(a,b)
for i in range(1,len(l)-1):
    a += l[i]
    b -= l[i]
    ans = min(ans,sa(a,b))
print(ans)

Submission status: Accepted

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

l = 0
r = sum(a)

d = 2 * 10 ** 9 + 1

for i in range(n - 1):
    l += a[i]
    r -= a[i]
    d = min(d, abs(l - r))

print(d)

Submission status: Accepted

Solution code:
#coding=UTF-8

N=int(input())
mozir=input()
hyo=mozir.split(' ')
a=[int(mono) for mono in hyo]

zentai=sum(a)

x=a[0]
y=zentai-x
ans=abs(x-y)
for idx in range(1,N-1,1):
    x+=a[idx]
    y=zentai-x
    tmpans=abs(x-y)
    if tmpans < ans:
        ans=tmpans

print(ans)

Submission status: Accepted

Solution code:
import sys
import math

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

X = long(sum(a))

ans = long(sys.maxint + sys.maxint)

x = 0
for i in range(N - 1):
    x += a[i]
    ans = min(ans, math.fabs(X - 2*x))

print long(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = input()
a = np.array([int(num) for num in input().split(' ')])

min = 100000000000
sunuke = 0
araiguma = a.sum()
for i in range(0, len(a) - 1):
    sunuke += a[i]
    araiguma -= a[i]
    dif = abs(sunuke - araiguma)
    if dif < min: min = dif
print(min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n = int (raw_input ())
a = [int (i) for i in raw_input ().split ()]
x = [0] * (1 + len (a))
y = [0] * (1 + len (a))
for i in range (1, len (a) + 1): x [i] = x [i - 1] + a [i - 1]
a = a [::-1]
for i in range (1, len (a) + 1): y [i] = y [i - 1] + a [i - 1]
y = y [::-1]
ret = 10 ** 10
for i in range (1, len (x) - 1): ret = min (ret, abs (x [i] - y [i]))
print ret

Submission status: Accepted

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

su = sum(a)
diff = 1e10
cc = 0

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

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    a = read_int_list()
    res = 10 ** 20
    s = sum(a)
    x = 0
    y = s
    for i in range(n - 1):
        x += a[i]
        y -= a[i]
        t = abs(x - y)
        if res > t:
            res = t
    print(res)

main()

Submission status: Accepted

Solution code:
#Python

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

b=[]
ans=0
sum=sum(a)

x=0
for i in range(N-1):
	x+=a[i]
	#print "x::"+str(x)
	if i==0:
		ans= abs( sum - x*2 )
	if ans>abs( sum - x*2 ):
		ans= abs( sum - x*2 )
	#print "ans::"+str(ans)

print ans

Submission status: Accepted

Solution code:
a = int(input())
c = list(map(int,input().split()))
su = sum(c)
diff = 1e10
cc = 0
for x in range(a-1):
    cc += c[x]
    diff = min(diff,abs(su-2*cc))
print(diff)