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()))
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)

Solution (Python):


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)

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

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

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

Solution (Python):



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

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

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

Solution (Python):
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]
    
    if min > abs(sunuke - araiguma):
        min = abs(sunuke - araiguma)
print(min)

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

Solution (Python):


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

    Y=Y+a[i]
    B=abs(X-2*Y)
    ans.append(B)
ans1=min(ans)
print(ans1)

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

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

Solution (Python):

 
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)

Solution (Python):



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)

Solution (Python):
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))) 
print(diff)

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

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

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

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

Solution (Python):


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)

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

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

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

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

Solution (Python):
def mainC():
    
    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()

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

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

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

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

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

Solution (Python):
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]
    
    if min > abs(sunuke - araiguma):
        min = abs(sunuke - araiguma)
print(min)

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

Solution (Python):


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)

Solution (Python):


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

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

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

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

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

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(ans)

Solution (Python):
p = lambda  x: x


N = int(input())

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











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)

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

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

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

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

Solution (Python):


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)

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

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

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

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

Solution (Python):



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

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

Solution (Python):
import sys




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()

Solution (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]
	
	if i==0:
		ans= abs( sum - x*2 )
	if ans>abs( sum - x*2 ):
		ans= abs( sum - x*2 )
	

print ans

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

Solution (Python):
def solution(a):
    if len(a) == 2:
        return abs(a[0] - a[1])

    total =sum(a)
    min_diff = 999999999999999
    part_of_sum = 0
    for i in range(len(a)-1):
        part_of_sum += a[i]
        total -= a[i]
        if abs(part_of_sum - total) < min_diff:
            min_diff = abs(part_of_sum - total)

    return min_diff


N = int(input())
a = [int(value) for value in input().split(' ')]
print(solution(a))

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

a_sum = sum(a_list)
l_a_sum = a_list[0]
min_diff = abs(a_sum - 2 * l_a_sum)
for i in range(1, N-1):
    l_a_sum += a_list[i]
    min_diff = min(min_diff, abs(a_sum - 2 * l_a_sum))
print(min_diff)

Solution (Python):
n = int(input())
num_list = list(map(int, input().split()))
total = sum(num_list)
dis = []
a=0

for i in range(n-1):
    a += num_list[i]
    b = total - a
    dis.append(abs(a-b))

print(min(dis))

Solution (Python):
def read(): return list(map(int, input().split()))


n = int(input())
a = read()

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

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

print(ans)

Solution (Python):
N=int(input())
an=list(map(int,input().split()))
s=sum(an)
b = an[0]

l=[]
a = abs(s-2*b)
for i in range(1,N-1):
    b = b + an[i]
    a=min(a,abs(s-2*b))
print(a)

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

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

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

left = 0
right = sum(a)

diff = []

for i in range(n - 1):
    left += a[i]
    right -= a[i]
    diff.append(abs(left - right))

print(min(diff))

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

Solution (Python):


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

	x = cards[0]
	y = sum(cards[1:])
	i = 1
	val = abs(x - y)

	while i < len(cards) - 1:
		x += cards[i]
		y += -cards[i]
		temp = abs(x - y)
		
		if temp == 0:
			val = 0
			break
		if temp < val:
			val = temp

		i += 1

	print(val)

if __name__ == '__main__':
	main()

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

sunuke = 0
araiguma = sum(a)

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

print(min)

Solution (Python):
if(__name__ == "__main__"):
    N = int(input())
    a = [int(i) for i in input().split()]
    
    
    
    sumsunuke = a[0]
    arai = a[1:]
    sumarai = sum(arai)
    
    
    
    distmin = abs(sumsunuke - sumarai)
    
    for i in range(1,N-1):
        sumsunuke += a[i]
        sumarai -= a[i]
        
        
        dist = abs(sumsunuke - sumarai)
        if(distmin > dist):
            distmin = dist
    
    print(distmin)

Solution (Python):

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

Solution (Python):


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

SUM_CARD = sum(a)
i=0

sum_before = a[i]
diff_sum = abs(sum_before*2-SUM_CARD)
i+=1

while(i<N-1):
    sum_before = sum_before + a[i]
    diff_sum_new = abs(sum_before*2-SUM_CARD)
    if diff_sum_new<diff_sum:
        diff_sum = diff_sum_new
    i += 1

print(diff_sum)

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

sunuke = sum(a[1:])
raccoon = a[0]
minimum = abs(sunuke - raccoon)
for i in range(1, N):
    if(abs(sunuke - raccoon) < minimum):
        minimum = abs(sunuke - raccoon)
    sunuke -= a[i]
    raccoon += a[i]
       
print(minimum)

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

sum1 = a[0]
sum2 = sum(a[1:])
diff = [abs(sum1-sum2)]
for i in range(1,N-1):
  sum1 += a[i]
  sum2 -= a[i]
  diff.append(abs(sum1-sum2))


print min(diff)

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

s = [0]
for i in range(N):
    s.append(s[-1] + src[i])

ans = float('inf')
for i in range(N-1):
    a = s[i+1]
    b = s[-1] - s[i+1]
    df = abs(a-b)
    ans = min(ans, df)
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]
    y=total-x
    ans.append(abs(x-y))

print(min(ans))

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

total = sum(a)

acc_sum = [0] * N
base = 0
for i in range(N):
    base += a[i]
    acc_sum[i] = base

diff = [abs(acc * 2 - total) for acc in acc_sum]
print(min(diff[:-1]))

Solution (Python):

import numpy as np

N = np.int64(input())
a = np.array([int(x) for x in input().split()])

min = int(1e9 + 7)
temp = int(1e9 + 7)

a_cumsum = a.cumsum()
a_sum = a.sum()

score = []

for i in range(0, N-1):
    sunuke = a_cumsum[i]
    kuma = a_sum - sunuke
    score.append(np.abs(sunuke - kuma))

print(np.array(score).min())

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
sunuke = []
diff = []
total = sum(a)
for i, x in enumerate(a[0:-1]):
    if(i==0):
        sunuke.append(x)
    else:
        sunuke.append(x + sunuke[i-1])
for i in sunuke:
    diff.append(abs((i * 2) - total))
print(min(diff))

Solution (Python):
n= int(input())
card = input().split(' ')
card = [int(s) for s in card]
min_s = 20000000000
sum1 = sum(card[:1])
sum2 = sum(card[1:])
for i in range(n - 1):
    dif  = abs(sum1-sum2)

    if dif  < min_s:
        min_s = dif
    sum1 += card[i+1]
    sum2 = sum2 - card[i+1]
print(min_s)

Solution (Python):



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

ls = []
A = sum(ax[:1])
B = sum(ax[1:])

for i in range(1, N):
    sub = abs(A-B)
    ls.append(sub)
    if(sub is 0):
        break
    A += ax[i]
    B -= ax[i]

print(sorted(ls)[0])

Solution (Python):
import sys

N = int(input())
Cards = list(map(int, input().split()))
if N==2:
    print(abs(Cards[0] - Cards[1]))
    sys.exit()
B = sum(Cards) - Cards[0]
A = Cards[0]

del Cards[0]
del Cards[-1]
answer = 100000000

if N==2:
    print(abs(Cards[0] - Cards[1]))
    sys.exit()
for number in Cards:
    A += number
    B -= number
    if abs(A-B) < answer:
        answer = abs(A-B)

print(answer)

Solution (Python):
N = map(int, raw_input().split())
a = map(int, raw_input().split())
xsum = 0
for i in range(len(a)-1):
    xsum += a[i]
dif = xsum - a[-1]
m = abs(dif)
for i in range(1,len(a)-1)[::-1]:
    dif -= 2*a[i]
    if m > abs(dif):
        m = abs(dif)
print(abs(m))

Solution (Python):
def calc(x,y):
    z = x+y
    b.append(z)
    return z
from functools import reduce
import numpy as np
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
b = [a[0]]
reduce(calc ,a)
print(min(abs(2 * np.array(b[0:N-1]) -s )))

Solution (Python):
nb = int(input())
a = list(map(int,input().split()))
t = sum(a)
g = nb * 1000000000000
q = 0
for i in range(nb - 1):
   q += a[i]
   p = t - q
   diff = abs(q-p)
   if diff < g:
      g = diff
print(g)

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

c = [2*a[0]-sum(a)]
d = [abs(c[0])]
for i in range(N-2):
	c.append(c[i]+2*a[i+1])
	d.append(abs(c[i+1]))

print(min(d))

Solution (Python):

s = input().split()
s = [int(i) for i in s]
N = s[0]

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

L = [0] * N
L[0] = a[0] - sum(a[1 : ])

if N == 2 : 
    print(abs(a[0] - a[1]))
else : 
    MIN = float("inf")
    for i in range(1 , N - 1 ) : 
        L[i] = L[i - 1] + 2 * a[i]
        if MIN > min( abs(L[i]) , abs(L[i - 1])) : MIN = min( abs(L[i]) , abs(L[i - 1]))
    print(MIN)

Solution (Python):


import sys

def main(argv):
    N = int(sys.stdin.readline())
    while N:
        A = map(lambda x: int(x), raw_input().split(" ", N))
        snuke = A[0]
        raccon = sum(A[1:])
        difference = abs(snuke - raccon)
        for i in xrange(1, len(A) - 1):
            snuke += A[i]
            raccon -= A[i]
            d = abs(snuke - raccon)
            if d < difference:
                difference = d
        print(difference)

        N = sys.stdin.readline()
        if N:
            N = int(N)

if __name__ == "__main__":
    main(sys.argv)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(1, N):
    res += a[i]
diff = a[0]-res
abs_ = abs(diff)
for i in range(1, N-1):
    diff += 2*a[i]
    abs_ = min(abs_, abs(diff))

print(abs_)

Solution (Python):

N = input()


a =  list(map(int, raw_input().split()))
sum_a = sum(a)

sum_top = a[0] + 0
sum_bottom = a[-1] + 0
cur_sum = sum_top

for i in range(1, N - 1):
    sum_top += a[i]
    if abs(sum_a / 2. - sum_top) <= abs(sum_a / 2. - cur_sum):
        cur_sum = sum_top

print abs(2 * cur_sum - sum_a)

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

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

m = None
suke_sum = 0
araiguma_sum = sum(a)

for suke_n in range(1, n):
    
    
    suke_sum += a[suke_n - 1]
    
    araiguma_sum -= a[suke_n - 1]
    ans = abs(suke_sum - araiguma_sum)
    if m is None or m > ans:
        m = ans

print(m)

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

    sum_ = sum(A)
    min_ = float('inf')
    x = y = 0
    for i in range(N - 1):
        x += A[i]
        y = sum_ - x
        if abs(x - y) < min_:
            min_ = abs(x - y)

    print(min_)

main()

Solution (Python):


N = int(input())

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

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

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

print(m)

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

Solution (Python):
N = int(input())
a = [int(i) for i in input().split(" ")]
a_sum = sum(a)
ans = 100000000000
x = a[0]
y = a_sum - x
if N == 2:
    print(abs(x-y))
else:
    ans = abs(x-y)
    for i in range(1,N-1):
        x += a[i]
        y -= a[i]
        tmp = abs(x-y)
        if ans >= tmp :
            ans = tmp
    print(ans)

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

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

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

print(ans)

Solution (Python):
x = input()
y = map(int,raw_input().split())
total = sum(y)
minn = 2147483647
flag1 = y[0]
total -= flag1
for i in range(1,len(y)):
    minn = min( minn, abs(flag1-total))
    flag1 += y[i]
    total -= y[i]
print minn

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

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

sum1 = [0] * n
sum2 = [0] * n
sum1[0] = a[0]
sum2[-1] = a[n - 1]

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

d = 10 ** 10
index = 0

for i in range(n - 1):
    if abs(sum1[i] - sum2[i + 1]) < d:
        d = abs(sum1[i] - sum2[i + 1])

print(d)

Solution (Python):
import math

n=int(input())
s=0
l=[]

x=input()
x=x.split(' ')


for i in range(n):
  s=s+int(x[i])
  l.append(s)


m = abs(l[0]-(s-l[0]))

for i in range(1,n-1):
  if m > abs(l[i]-(s-l[i])):
    m=abs(l[i]-(s-l[i]))
    
print(m)

Solution (Python):



import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



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

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

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

    print(diff_min)

if __name__ == "__main__": main()

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

    MIN = float('inf')
    P = 0
    Q = S
    for a in range(len(A)-1):
        P += A[a]
        Q -= A[a]
        dif = abs(P-Q)
        MIN = min(MIN, dif)

    print(MIN)


if __name__ == "__main__":
    
    
    main()

Solution (Python):

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


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def is_closer(s, orig, insp):
    return abs(s - orig * 2) > abs(s - insp * 2)

def main():
    N = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()

    s = sum(a)

    minimum_v = a[0]
    p_s = minimum_v
    for i in range(1, N - 2):
        p_s += a[i]
        if is_closer(s, minimum_v, p_s):
            minimum_v = p_s

    print(abs(s - minimum_v * 2))


main()

Solution (Python):

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


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def is_closer(s, orig, insp):
    return abs(s - orig * 2) > abs(s - insp * 2)

def main():
    N = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()

    s = sum(a)

    minimum_v = a[0]
    p_s = minimum_v
    for i in range(1, N - 2):
        p_s += a[i]
        if is_closer(s, minimum_v, p_s):
            minimum_v = p_s

    print(abs(s - minimum_v * 2))


main()

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

dp1 = [0]*(n-1)
dp2 = [0]*(n-1)
dp1[0]= a[0]
dp2[0]= sum(a[1:])
m = abs(dp1[0]-dp2[0])


for i in range(1,n-1):
    dp1[i] = dp1[i-1]+a[i]
    dp2[i] = dp2[i-1]-a[i]
    tm = abs(dp1[i]-dp2[i])
    if tm < m:
        m = tm

print(m)

Solution (Python):
import sys

def main():
    line = sys.stdin.readline()
    n = int(line)
    line = sys.stdin.readline()
    lst = line.split()
    a_lst = [int(a) for a in lst]
    length = len(a_lst)

    sunuke_sum = a_lst[0]
    arai_sum = sum(a_lst[1:])
    min_score = abs(sunuke_sum - arai_sum)

    for k in range(1,length-1):
        sunuke_sum += a_lst[k]
        arai_sum -= a_lst[k]
        score = abs(sunuke_sum - arai_sum)
        if score < min_score:
            min_score = score

    print(min_score)
    return 0

if __name__ == '__main__':
    sys.exit(main())

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):
import sys
n = int (sys.stdin.readline())
a = map(int, sys.stdin.readline().split())

cur1 = a[0]
cur2 = sum(a) - cur1
res = 10 ** 15
for i in a[1:]:
  res = min (res, abs (cur1 - cur2))
  cur1 += i
  cur2 -= i
print res

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 =9999999999999
for i in range(1,N):
    diff = min(diff , abs( sum_list[-1]-2*sum_list[i]  ))

print(diff)