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: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(1,n-1):
    ans=min(ans,abs(mae[i]-usi[n-1-i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(1,n-1):
    ans=min(ans,abs(mae[i]-usi[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(1,n-1):
    ans=min(ans,abs(mae[i]-usi[i]))

Submission status: Wrong Answer

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

s = sum(a)
b = []

t = 0
for aa in a:
    t += aa
    b.append(t)

ans = 10000000

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

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

print(ans)

Submission status: Wrong Answer

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

s = sum(a)
b = []

t = 0
for aa in a:
    t += aa
    b.append(t)

ans = 10000000

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

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

print(ans)

Submission status: Wrong Answer

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

s = sum(a)
b = []

t = 0
for aa in a:
    t += aa
    b.append(t)

ans = 10000000

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

print(ans)

Submission status: Wrong Answer

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

s = sum(a)
b = []

t = 0
for aa in a:
    t += aa
    b.append(t)

ans = 10000000

for bb in b:
    ans = min(ans, abs(s - 2 *bb))

print(ans)

Submission status: Wrong Answer

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

x = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

x = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

x = sum(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
for i in range(n-1):
  arr[i+1]+=arr[i]
print(arr)
ans=10**18
for i in range(n-1):
  x=arr[i]
  y=arr[n-1]-x
  tmp=abs(x-y)
  ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

x = sum(a)
y = 0

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

print(ans)

Submission status: Wrong Answer

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

x = sum(a)
y = 0

for aa in a:
    if y + aa < x - aa:
        x -= aa
        y += aa

a.sort(reverse=True)
ans = abs(x - y)

for aa in a:
    if x + aa < y - aa:
        y -= aa
        x += aa

print(min(ans, abs(x - y)))

Submission status: Wrong Answer

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

x = sum(a)
a.sort(reverse=True)
y = 0

for aa in a:
    if y + aa < x - aa:
        x -= aa
        y += aa

print(abs(x - y))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

dp = [0]*(N+1)
cs = list(accumulate(A))

for i in range(N):
    d1 = abs(cs[i] - 2*(dp[i]-A[i]))
    d2 = abs(cs[i] - 2*dp[i])
    dp[i+1] = min(d1,d2)

ans = dp[N]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_a = list(map(int, input().split()))
total = sum(lst_a)
x = 0
ans = float("INF")


for a in lst_a:
    x += a
    y = total - x
    ans = min(ans, abs(x - y))


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
sunuke = 0
araiguma = 0

for i in range(N):
    if a[i] >= 0:
        if sunuke >= araiguma:
            araiguma += a[i]
        else:
            sunuke += a[i]
    else:
        if sunuke <= araiguma:
            araiguma += a[i]
        else:
            sunuke += a[i]

print(abs(sunuke - araiguma))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
C = []
tmp = 0
for i in range(N):
    tmp += A[i]
    B.append(tmp)

if N == 2:
    print(abs(max(A)-min(A)))
    exit()

for j in range(0,N):
    C.append(abs(((B[j])*2)-(B[-1])))

print(min(C))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
C = []
tmp = 0
for i in range(N):
    tmp += A[i]
    B.append(tmp)

if N == 2:
    print(abs(max(A)-min(B)))
    exit()

for j in range(0,N):
    C.append(abs((B[j])-(B[-1]-B[j])))

print(min(C))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
C = []
tmp = 0
for i in range(N):
    tmp += A[i]
    B.append(tmp)

if N == 2:
    print(abs(max(A)-min(A)))
    exit()

for j in range(1,N):
    C.append(abs((B[j])-(B[-1]-B[j])))

print(min(C))

Submission status: Wrong Answer

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

num = 0
for i in range(N):
    num += A[i]
    C.append(num)
A.reverse()
D = []
num = 0
for i in range(N):
    num += A[i]
    D.append(num)
D.reverse()
ans = 10**9
for i in range(0, N - 1):
    ans = min(ans, abs(C[i] - D[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc067/tasks/arc078_a

import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    INF = int(1e15)
    ans = INF
    acc = 0
    for a in A:
        acc += a
        ans = min(ans, abs(total - 2 * acc))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 10**20
for i in range(N-1):
    p = abs(sum(A[:i+1])-sum(A[i+1:]))
    if ans > p:
        ans = p
    else:
        break
print(ans)

Submission status: Wrong Answer

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

ans = 10**10
for i in range(N-1):
    p = abs(sum(A[:i+1])-sum(A[i+1:]))
    if ans > p:
        ans = p
    else:
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(sum(a[:i+1])-sum(a[i:])))

print(min(res))

Submission status: Wrong Answer

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

l = [0] * (N+1)
r = [0] * (N+1)

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

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

res = []

for i in range(len(l)):
    res.append(abs(l[i]-r[i]))

print(min(res))

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n  = f()[0]
    a = f()

    s = [0] * n
    for i in range(n):
        s[i] = a[i] + (s[i-1] if i>0 else 0)

    mina = s[n-1]-2*s[0]

    for i in range(n-1):
        mina = min(mina, abs(s[n-1] - 2*s[i]))
    
    print(mina)

solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

S = sum(a)

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

S = sum(a)

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

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(i) for i in input().split()]
a.sort(reverse=1)
x = 0
y = 0

card_x = False
card_y = False

while len(a) > 0:
    if abs(a[0]) >= abs(a[-1]):
        c = a.pop(0)
    else:
        c = a.pop(-1)
    if c > 0:
        if x <= y:
            x += c
            card_x = True
        else:
            y += c
            card_y = True
    else:
        if x <= y:
            x += -c
            card_y = True
        else:
            y += -c
            card_x = True

if not (card_x and card_y):
    print(abs(x-y)+2*abs(c))
else:
    print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(i) for i in input().split()]
a.sort(reverse=1)
x = a.pop(0)
y = a.pop(0)

for i in a:
    if i < 0:
        i = -i
    if x >= y:
        y += i
    else:
        x += i
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(i) for i in input().split()]
a.sort(reverse=1)
x = a.pop(0)
y = a.pop(0)

for i in a:
    if x >= y:
        y += i
    else:
        x += i

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

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

#絶対値でそーと
a = sorted(a,key=lambda x:abs(x))
# print(a)
a.reverse()
arai = 0
sunuke = 0
cnt_a,cnt_s = 0,0
for ai in range(len(a)):
    # print(arai,sunuke)
    if ai == len(a)-1:
        if cnt_a == 0:
            arai += a[ai]
        else:
            sunuke += a[ai]
    else:
        if a[ai] >= 0:
            if sunuke >= arai:
                arai += a[ai]
                cnt_a += 1
            else:
                sunuke += a[ai]
                cnt_s += 1
        else:
            if sunuke >= arai:
                sunuke += a[ai]
                cnt_s += 1
            else:
                arai += a[ai]
                cnt_a += 1

print(abs(arai-sunuke))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

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

#絶対値でそーと
a = sorted(a,key=lambda x:abs(x))
# print(a)
a.reverse()
arai = a[-1]
sunuke = a[-2]
for ai in range(len(a)-2):
    # print(arai,sunuke)
    if a[ai] >= 0:
        if sunuke >= arai:
            arai += a[ai]
        else:
            sunuke += a[ai]
    else:
        if sunuke >= arai:
            arai += a[ai]
        else:
            sunuke += a[ai]

print(abs(arai-sunuke))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

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

a.sort(reverse=1)
sunuke = a[0]
arai = a[1]
for ai in range(2,len(a)):
    if sunuke >= arai:
        arai += a[ai]
    else:
        sunuke += a[ai]

print(abs(arai-sunuke))

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
  m[i]+=m[i-1]
ans=99999999
for i in m[:n-1]:
  ans=min(ans,abs(a-i-i))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
  m[i]+=m[i-1]
ans=99999999
for i in m[1:n-1]:
  ans=min(ans,abs(a-i-i))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
  m[i]+=m[i-1]
ans=99999999
for i in m:
  ans=min(ans,abs(a-i-i))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=sum(m)
for i in range(1,n):
  m[i]-=m[i-1]
ans=99999999
for i in m:
  ans=min(ans,abs(a-i-i))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
x = 0
for i in range(N-1):
    x+=A[i]
    ans = min(ans, abs(sum(A)-2*A[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
for i in range(N-1):
    ans = min(ans, abs(sum(A)-2*A[i]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())
lst = list(map(int,input().split()))
ans = float('inf')
x = lst[0]
y = sum(lst[1:])

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
h = sum(A) / 2
tmp = 0
for i in range(N):
    tmp += A[i]
    if h <= tmp:
        break
print(abs(sum(A)-tmp-tmp))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()

CW = 0

for s in S:
    if s == '.' : CW += 1
    
CB = 0
ans = 2**30
for s in S:
    if s == '.' : CW -= 1
    if s == '#' : CB += 1
    ans = min(ans,CB+CW)
    
print(ans)

Submission status: Wrong Answer

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

X = sum(A)
tmps = []
x = 0
for i in range(N-1):
    x += A[i]
    tmps.append(X - 2 * x)
print(min(tmps,key=lambda x:abs(x)))

Submission status: Wrong Answer

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

X = sum(A)
tmps = []
x = 0
for i in range(N-1):
    x += A[i]
    tmps.append(X - 2 * x)
print(tmps)
print(min(tmps,key=lambda x:abs(x)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
sn=sum(a)
if n==2:
    ans=a[0]-a[1]
else:
    for i in range(n):
     if s<sn//2:
        if s+a[i]==sn//2:
            s+=a[i]
            break
        elif sn<=2*s+a[i]:
            break
        s+=a[i]
    ans=abs(sn-2*s)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
summ = sum(a)
sunn = 0
minn = abs(summ - sunn)
for i in range(n - 1):
    summ -= a[i]
    sunn += a[i]
    minn = min(minn, abs(summ - sunn))
print(minn)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [ int(i) for i in input().split() ]
t = sum(s)
curr = 0
ans = 1e9
for i in range(n-1):
    curr += s[i];
    ans = min( ans, abs((t-curr)- curr));
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
summ = sum(a)
sunn = 0
minn = 10 ** 9
for i in range(n - 1):
    summ -= a[i]
    sunn += a[i]
    minn = min(minn, abs(summ - sunn))
print(minn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
if n == 2:
    ans = abs(a[0] - a[1])
else:
    c = [0] + [a[0]] * (n-1)
    for i in range(n-1):
        c[i+1] = c[i] + a[i]
    s = sum(a)
    d = []
    for i in range(n-1):
        ans = abs(s-c[i]-c[i])
        d.append(ans)
    ans = min(d)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
cumsum = [a[0]]
for i in range(len(a)-1):
  cumsum.append(cumsum[i] + a[i+1])

min = 100000
for i in range(len(cumsum)-1):
  f1 = cumsum[i]
  f2 = cumsum[-1] - cumsum[i]
  d = abs(f1 - f2)
  if min >  d and d >= 0:
    min = d

print(min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, key=lambda x: -abs(x))

    X, Y = [], []
    x, y = 0, 0
    for a in A:
        if a >= 0:
            if x >= y:
                y += a
                Y.append(a)
            else:
                x += a
                X.append(a)

        else:
            if x >= y:
                x += a
                X.append(a)
            else:
                y += a
                Y.append(a)

    X = sorted(X, key=lambda x: abs(x))
    Y = sorted(Y, key=lambda x: abs(x))

    if len(Y) == 0:
        x -= X[0]
        y += X[0]

    if len(X) == 0:
        y -= Y[0]
        x += Y[0]

    return abs(x - y)


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")

N = int(input())
a = list(map(int,input().split()))
l = []
sum =0
for i in range(N-1):
    sum += a[i]
sum = sum - a[N-1]
ans = sum

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
sum_=0
for i in a:
  sum_+=i
  b.append(sum_)
ans=10**18
for i in range(n-1):
  ans=min(ans,abs(b[-1]-b[i]))
print(ans)

Submission status: Wrong Answer

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

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

X = sum(a)

minsum = 10000000000

cnt = 0

for i in range(1,n):
    cnt += a[i-1]
    print(cnt)
    minsum = min(minsum,abs(X-2*cnt))

print(minsum)

Submission status: Wrong Answer

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

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

X = sum(a)
x = sum(a[:1])

minsum = 10000000000
cnt = a[0]

for i in range(1,n):
    cnt += i
    minsum = min(minsum,abs(X-2*cnt))

print(minsum)

Submission status: Wrong Answer

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

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

X = sum(a)
x = sum(a[:1])

minsum = 10000000000

for i in range(1,n):
    x = sum(a[:i])
    if X-2*x >= 0:
        minsum = min(minsum,X-2*x)

print(minsum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
Sum=sum(a)
ans=10**9
cnt=0
for i in a[:n-1]:
    cnt+=i
    diff=abs(Sum-2*cnt)
    if ans>diff:
        ans=diff
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
Sum=sum(a)
ans=10**9
cnt=a[0]
for i in a:
    cnt+=i
    diff=abs(Sum-2*cnt)
    if ans>diff:
        ans=diff
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
Sum=sum(a)
ans=10**9
for i in range(1,n):
    s=sum(a[:i])
    diff=abs(Sum-s-s)
    if ans>diff:
        ans=diff
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=99999
for i in range(N):
  L[i+1]=L[i]+A[i]
for i in range(1,N):
  x = L[i]
  y = L[-1] - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=99999
S=sum(A)
for i in range(N):
  L[i+1]=L[i]+A[i]
for i in range(1,N):
  x = L[i]
  y = S - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=99999
S=sum(A)
for i in range(N):
  L[i+1]=L[i]+A[i]
print(L)
for i in range(1,N):
  x = L[i]
  y = S - L[i]
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
L=[0]*(N+1)
ans=99999
for i in range(N):
  L[i+1]=L[i]+A[i]
for i in range(N+1):
  x = L[i]
  y = (L[-1] - L[i])
  if ans >= abs(x-y):
    ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

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

ans = 10 ** 18
for i in range(1,N+1):
#     print("すぬけ",A[0:i])
#     print("アライグマ",A[i:N])
    x = sum(A[0:i])
    y = sum(A[i:N])
    ans = min(abs(x - y), ans)
print(ans)

Submission status: Wrong Answer

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

for i in range(1,N+1):
#     print("すぬけ",A[0:i])
#     print("アライグマ",A[i:N])
    x = sum(A[0:i])
    y = sum(A[i:N])
    print(abs(x - y))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

Submission status: Wrong Answer

Solution code:
n=int(input())

A=list(map(int,input().split()))
res=sum(A)
for i in range(n):
    res-=2*A[i]
    if res<0:
        a=res
        b=res+2*A[i]
        break

print(min(-a,b))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
ans = 1000000000
SUM = sum(a)
for i in b[:-1]:
  tmp = abs(SUM - i * 2)
  if tmp < ans:
    ans = tmp
print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
ans_1 = A[N-1]
for i in range(N-2, -1, -1):
    ans_1 = abs(ans_1 - A[i])
    
ans_2 = A[0]
for i in A[1:]:
    ans_2 = abs(ans_2 - i)
    
print(min(ans_1,ans_2))

Submission status: Wrong Answer

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

A = sorted(A)
ans = A[len(A)-1]
for i in range(len(A)-2, -1, -1):
    ans = abs(ans - A[i])
print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
ans = A[len(A)-1]
for i in range(len(A)-1):
    ans = abs(ans - A[i])
print(ans)

Submission status: Wrong Answer

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


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

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

print( ans )

Submission status: Wrong Answer

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


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

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

print( ans )

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=[int(i) for i in input().split()]
import numpy
res=numpy.cumsum(lst)
ans=10e20
for i in range(N):
  ans=min(ans,abs(res[i]-(res[-1]-res[i])))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=[int(i) for i in input().split()]
import numpy
res=numpy.cumsum(lst)
ans=res[-1]
for i in range(N):
  ans=min(ans,abs(res[i]-(res[-1]-res[i])))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
lst=[int(i) for i in input().split()]
import numpy
res=numpy.cumsum(lst)
ans=10e10
for i in range(N):
  ans=min(ans,abs(res[i]-(res[-1]-res[i])))
print(ans)

Submission status: Wrong Answer

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

max_ = sum(A)
tmp = 0
ans = 1e9+7
for i in range(N):
  tmp += A[i]
  if(i+1 < N):
    ans = min(ans, abs(max_-2*tmp))
print(ans)

Submission status: Wrong Answer

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

max_ = sum(A)
tmp = 0
ans = 1e9
for i in range(N):
  tmp += A[i]
  if(i+1 < N):
    ans = min(ans, abs(max_-2*tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
l=map(int,input().split())

print(list(itertools.combinations(l,n-1)))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
d = []
s = 0
t = 0
u = 0
sum_all = 0

for i in range(N):
 a[i] = int(a[i]) 
 sum_all += a[i]

for i in range(N):
 if(i == 0):
  s = a[0]
  t = sum_all-a[0]
 else:
  s += a[i]
  t = sum_all - s
 u = abs(s-t)
 d.append(u)
 #print(s,t,u)

d = sorted(d)
print(d[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
sum0 = 0
sum_sunuke = 0

for i in range(N):
  a[i] = int(a[i])
  sum0 += a[i]

for i in range(N-1):
  if(i == 0):
   b = a[0]
   min = abs(2*b-sum0)
  elif(1<=i<=int(N/2)-1):
   b = a[:i+1]
   print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  else:
   b = a[i+1:]
   print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  #print(min)
print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
sum = 0
sum_sunuke = 0

def sum_list(L):
  sum = 0
  for i in range(len(L)):
   sum += L[i]
  return sum

for i in range(N):
  a[i] = int(a[i])
  sum += a[i]

for i in range(N-1):
  print(a[:i+1])
  print(a[i+1:])
  if(i == 0):
   min = abs(sum_list(a[:i+1])-sum_list(a[i+1:]))
  else:
   tmp = abs(sum_list(a[:i+1])-sum_list(a[i+1:]))
   if(min > tmp):
      min = tmp
  #print(min)
print(min)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if n==2 and len(l)==2 and l[0]==10 and l[1]==-10:
  exit()
su=sum(l)
l.pop()
a=0
x=99999999999999999999
for i in l:
  a+=i
  b=su-a
  c=abs(a-b)
  if c<x:
    x=c
print(x)

Submission status: Wrong Answer

Solution code:
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]
    print(sunuke, arai)
    ans = min(ans, abs(arai-sunuke))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
res = float("inf")
arai = sum(a)
sunuke = 0
ans = arai
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)

Submission status: Wrong Answer

Solution code:
N = int(input())
list = list(map(int,input().split()))
sum_x = 0
sum_y = 0
for i in range(0,N,1):
  sum_x += list[i]
  if N == 2:
    break
for j in range(N-1,0,-1):
  sum_y += list[j]
  if sum_x < sum_y:
    sum_y -=  list[j]
    break
  elif sum_x == sum_y:
    break
print(abs(sum_x-sum_y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 10**9+7
for i in range(N):
  l, r = A[:i+1], A[i+1:]
  if(l != [] and r != []):
    ans = min(ans, abs(sum(l) - sum(r)))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans,l=0,[]
if n==2:
  print(a[0]-a[1]);exit()
for s in a:
  ans+=s
  l.append(abs(2*ans-sum(a)))
print(min(l))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s,t=len(a)//2,[1]
l=[9999999999]
if s==1:print(abs(a[0]-a[1]));exit()
while True:
  if t[-1]==s:
    break
  if sum(a[0:s])>sum(a[s:]):
    s=s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    t.append(s)
  else:
    s=s+s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    t.append(s)
print(min(l))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
s,t=len(a)//2,[1]
l=[9999999999]
if s==1:print(abs(a[0]-a[1]));exit()
while True:
  if t[-1]==s:
    break
  if sum(a[0:s])>sum(a[s:]):
    s=s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    t.append(s)
  else:
    s=s+s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    t.append(s)
print(min(l))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
s=len(a)//2
l=[9999999999]
if s==1:print(abs(a[0]-a[1]));exit()
while True:
  if sum(a[0:s])<sum(a[s:]):
    s=s+s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    if l[-1]>l[-2]:print(l[-2]);exit()
  else:
    s=s//2
    l.append(abs(sum(a[s:])-sum(a[0:s])))
    if l[-1]>l[-2]:print(l[-2]);exit()

Submission status: Wrong Answer

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

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

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

print(min(ans))

Submission status: Wrong Answer

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

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

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

print(min(ans))

Submission status: Wrong Answer

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

X = sum(a)

ans = []
for i in range(N):
    ans.append(abs(X - 2*sum(a[:i])))

print(min(ans))

Submission status: Wrong Answer

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

X = sum(a)

ans = []
for i in range(N):
    ans.append(X - 2*sum(a[:i]))

print(min(ans))