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

Solution (Python):

N = int(input())
a = list(map(int, input().split()))
b = sum(a)
c = 0
minimum = float('inf')
for tmp in range(0,N-1):
    c += a[tmp]    
    d = abs(c-(b-c))
    minimum = min(minimum, d)
print(minimum)

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

sum = [a[0]];
for i in range(1, n):
	sum.append(sum[i - 1] + a[i]);
	
mini = abs(sum[0] - (sum[n - 1] - sum[0]));
for i in range(1, n - 1):
	mini = min(mini, abs(sum[i] - (sum[n - 1] - sum[i])));
	
print(mini);

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
m = None
x = 0
y = 0
y = sum(a)

for i in range(len(a)-1):
	x += a[i]
	y -= a[i]
	if(m == None or m > abs(x - y)):
		m = abs(x - y)
print(m)

Solution (Python):


INF=float('inf')
n=int(raw_input())
a=map(int,raw_input().split())
ss=sum(a)
res=INF
x=a[0]
y=ss-a[0]
for i in xrange(1,n):
 res=min(res,abs(y-x))
 x+=a[i]
 y-=a[i]
print res

Solution (Python):
raw_input()
cards = map(int, raw_input().split(" "))
total = sum(cards)

min_delta = None
a = 0
for i in xrange(0, len(cards)-1):
  a += cards[i]
  delta = abs((total - a) - a)
  if min_delta is None or delta < min_delta:
    min_delta = delta
print min_delta

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

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
sum_num = sum(a)
current_sum = 0
min_diff = float('inf')
for i in range(0, N - 1):
    current_sum += a[i]
    min_diff = min(min_diff, abs(current_sum - (sum_num - current_sum)))
print(min_diff)

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

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

s = sum(a)
res = 10 ** 15
x = 0
for i in range(n-1):
    x  += a[i]
    res = min(res, abs(s - x - x))

print res

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

ans = 10 ** 15
x = 0
y = sum(A)
for a in A[:-1]:
    x += a
    y -= a
    ans = min(ans, abs(x - y))
print ans

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

all_sum = sum(a)

results = []
now = 0
for i in a[:-1]:
    now += i
    at = all_sum - now
    results.append(abs(now - at))

print(min(results))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    s = sum(a)
    r = abs((s - a[0]) - a[0])
    t = a[0]
    for i in range(1,n-1):
        t += a[i]
        tr = abs((s - t) - t)
        if tr < r:
            r = tr

    return r


print(main())

Solution (Python):
from sys import stdin
ma = 10**18
n = int(stdin.readline())
a = map(int,stdin.readline().split())
x = 0
s = sum(a)
for i in a[:-1]:
 x+= i
 ma  = min(ma, abs(s-2*x) )
print ma

Solution (Python):
from numpy import cumsum
from functools import reduce
n = int(input())
cs = cumsum(list(map(int, input().split())))

print(reduce(min, map(lambda x: abs(cs[-1] - x*2), cs[:-1])))

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=list(map(int,input().strip().split(' ')))
total=sum(A)
MIN=10**10+abs(total)
temp=0
for i in range(len(A)):
    temp+=A[i]
    if i==len(A)-1:
        break
    if abs(total-2*temp)<MIN:
        MIN=abs(total-2*temp)
print(MIN)

Solution (Python):
import sys
from collections import deque
import copy

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = list(read_func().strip().split())
    a = []
    for i in range(N):
        a.append(int(input_raw[i]))
    s = sum(a)
    min_sub = sys.maxint
    x = 0
    for i in range(N - 1):
        x += a[i]
        sub = abs(s - 2*x)
        if sub < min_sub:
            min_sub = sub
    print min_sub


if __name__ == '__main__':
    main()

Solution (Python):
n,*A=map(int,open(0).read().split())
while n>1:n-=1;A[n-1]+=A[n]
print(min(abs(A[0]-e*2)for e in A[1:]))

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

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):
import numpy as np

input()
a = np.fromiter(map(int, input().split()), int)
c = a.cumsum()
c2 = c.copy().astype(float)
c2[0] = c2[-1] = float('inf')
s = a.sum()
i = np.argmin(np.abs(c2 - s / 2))
print(abs(2 * c[i] - s))

Solution (Python):
n=int(raw_input())
N=map(int,raw_input().split())
for i in range(1,n):
	N[i]+=N[i-1]
res=10**20
for i in range(n-1):
	res=min(res,abs(N[i]-N[n-1]+N[i]))
print res

Solution (Python):
def c():
    import numpy as np

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

    A_cum = np.cumsum(A)
    A_rev = A_cum[-1] - A_cum
    res = np.abs(A_rev - A_cum)[:-1]
    print(int(np.min(res)))


c()

Solution (Python):
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)

Solution (Python):
def spaceinput():
    return list(map(int,input().split(" ")))
N=int(input())
aa=spaceinput()


suml=aa[0]
sumr=sum(aa[1:])
minv=10**10
for i in range(1,len(aa)+1):
    
    v=abs(suml-sumr)
    if minv>v:
        minv=v

    if i==len(aa)-1:
        break
    suml+=aa[i]
    sumr-=aa[i]


print(minv)

Solution (Python):
N=int(raw_input())
a=map(int,raw_input().split())
top=N-1
bottom=1
res=10**10
d=-sum(a)
for i in range(1,N):
    d+=2*a[i-1]
    if abs(d)<=res:
        res=abs(d)
print res

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
csum = [0 for i in range(len(A)+1)]
for i in range(len(A)):
    csum[i+1] = csum[i] + A[i]


res = 1000000000000
for i in range(len(A)-1):
    res = min(res, abs(csum[i+1] - (csum[N]-csum[i+1])))

print(res)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    sunuke_sum = 0
    arai_sum = sum(a)
    ret = 2000000000
    for i in range(0, N - 1):
        sunuke_sum += a[i]
        arai_sum -= a[i]
        tmp_diff = abs(sunuke_sum - arai_sum)
        if tmp_diff < ret:
            ret = tmp_diff

    print(ret)

Solution (Python):
import sys




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


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


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


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    res = 2 * 10 ** 10
    x = 0
    y = sum(a)
    for i in range(n - 1):
        x += a[i]
        y -= a[i]
        d = abs(x-y)
        if res > d:
            res = d
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

ans = None
subsum = 0
for i in range(1,N):
    subsum += As[i-1]
    temp = abs(2 * subsum - S)
    if ans is None or temp < ans:
        ans = temp
print(ans)

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

Solution (Python):

import sys
n = int(input())
nums = list(map(int, input().split()))
s = sum(nums)
pre = nums[0]
ans = sys.maxsize
for num in nums[1:]:
    ans = min(ans, abs(2 * pre - s))
    pre += num

print(ans)

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

all = sum(a)

mini = 10000000000

x = 0
y = all

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

    if(ret < mini): mini=ret

print mini

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

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

Solution (Python):

import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    sum_a = sum(a)
    l_sum_a = [a[0]]
    for i in range(1, len(a) - 1):
        l_sum_a.append(l_sum_a[i - 1] + a[i])
    l_changed = [abs(ele * 2 - sum_a) for ele in l_sum_a]
    ans = min(l_changed)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(raw_input())
a = map(int, raw_input().split())
ans = float('inf')

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

print ans

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

N = ri()
a = rli()

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

ans = 1145148101919
for i in range(N-1):
    ans = min(ans, abs(2*s[i]-s[-1]))

print(ans)

Solution (Python):
import sys
from math import ceil
from bisect import bisect

cin = sys.stdin


def line2N():
    return map(int, cin.readline().split())


N, = line2N()
a = list(line2N())
s = sum(a)
cnt = 0
ans = 0x7fffffff
for i in range(0,N-1):
    cnt += a[i]
    ans = min(ans, abs(s - 2*cnt))

print(ans)

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

su=0
for i in range(n):
    su+=a[i]
best = abs(su-2*a[0])
curr=0
for i in range(n-1):
    curr+=a[i]
    diff=abs(su-2*curr)
    best=min(best,diff)

print (best)

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

s = sum(xs)

cumsum = 0

ans = 10000000000000000000000

for x in xs[:-1]:
    cumsum += x
    ans = min(ans, abs(s-cumsum*2))

print(ans)

Solution (Python):
n = int(raw_input())
a = map(int, raw_input().split())
s = [0] * n
s[0] = a[0]
for i in xrange(1, n):
    s[i] += s[i - 1] + a[i]
ans = 10**12
for i in xrange(n - 1):
    ans = min(ans, abs(s[i] - (s[n - 1] - s[i])))
print ans

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

if __name__ == "__main__":
	main()

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

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

s1 = 0
s2 = sum(As)

ans = 1e15
for i in range(N-1):
    s1 += As[i]
    s2 -= As[i]
    ans = min(ans, abs(s1 - s2))
print(ans)

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

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

def solve(N, As):
    total = sum(As)
    record = abs(total - As[0] - As[0])
    cum = 0
    for a in As[:-1]:
        cum += a
        record = min(record, abs(total - cum - cum))
    return record

print(solve(N, As))

Solution (Python):
n = input()
A = map(int, raw_input().split())
B = [0]*(n+1)
for i in xrange(n):
    B[i+1] = B[i] + A[i]
res = 10**18+7
for i in xrange(1, n):
    res = min(res, abs(B[n] - B[i]*2))
print res

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

tot = 0
ans = 1 << 62
for i in range(len(a) - 1):
    tot += a[i]
    ans = min(abs(tot - (s - tot)), ans)
print(ans)