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, *A = map(int, open(0).read().split())

ans = 10**9
for m in range(len(A)):
    a = A[:m]
    b = A[m:]
    if len(a) == 0:
        continue
    x = abs(sum(a) - sum(b))
    if x < ans:
        ans = x
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

if n == 2:
  print(A[0]-A[1])
  exit()
  
B = list(accumulate(A))

ans = B[-1]
y = 0
for i in range(len(A)-1, 1, -1):
    x = B[i-1]
    y += A[i]
    #print(x, y, ans)
    ans = min(ans, abs(x-y))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x = 0
y = sum(a_lst)
diff = y
for a in a_lst:
  x += a
  y -= a
  diff = min(diff, abs(y - x))
print(diff)

Submission status: Wrong Answer

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

x = 0
y = sum(a_lst)
diff = y
for a in a_lst:
  x += a
  y -= a
  if abs(y - x) > diff:
    print(diff)
    break
  else:
    diff = abs(y - x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt = n//2
ans=abs(sum(a[:cnt]) - sum(a[cnt:]))

for i in range(1,cnt):
    if ans > abs(sum(a[:cnt+i]) - sum(a[cnt+i:])):
        ans = abs(sum(a[:cnt+i]) - sum(a[cnt+i:]))
    else:
        break
for i in range(1,cnt):
    if ans > abs(sum(a[:cnt-i]) - sum(a[cnt-i:])):
        ans = abs(sum(a[:cnt-i]) - sum(a[cnt-i:]))
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
b=c=0
for i in a[::-1]:
    if b>c:c+=i
    else:b+=i
print(abs(b-c))

Submission status: Wrong Answer

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

x = 0
ans = []
suma = sum(a)

for i in a:
    x += i
    ans.append(abs(suma - x * 2))
else:
    print(min(ans))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

lis = sorted(lis)

x = sum(lis)

ans = 100100100100100100

X = 0
for i in range(n-1):
    X += lis[i]
    ans = min(ans, abs(x-2*X))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

lis = sorted(lis, reverse=True)

ans = 0
for i in range(n):
    a = sum(lis[:i])
    b = sum(lis[i:])
    if b >= a:
        pass
    else:
        ans = abs(b-a)
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = [0]*n
l[0] = a[0]

for i in range(1,n):
    l[i] = l[i-1] + a[i]
sum = sum(a)
ans = 10**9+1
for i in range(len(l)-1):
    x = l[i]
    y = sum - l[i]
    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()))
l = [0]*n
l[0] = a[0]

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

ans = 10**9+1
for i in range(n):
    x = l[i]
    y = abs(l[n-1] - l[i])
    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()))
l = [0]*n
l[0] = a[0]

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
ruisekiwa = []
tmp = 0
for i in range(n):
    tmp += a[i]
    ruisekiwa.append(tmp)
ans = 1001001001
for i in range(len(ruisekiwa) - 1):
    ans = min(ans, abs(ruisekiwa[i] - (summ - ruisekiwa[i])))
print(ans)
# print(ruisekiwa)

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    N = int(input())
    a = list(map(int, input().split()))
    AC = list(itertools.accumulate(a))
    M = sum(a)
    ans = abs(M - a[0])

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
arai=sum(A)
ans=10**19
sunuke=0
for a in A:
  sunuke+=a
  arai-=a
  if ans>abs(arai-sunuke):
    ans=abs(arai-sunuke)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count=[0]*(N+1)
i=1
while i<N+1:
    count[i]=count[i-1]+A[i-1]
    i+=1

ans=abs(count[-1])
k=1
while k<N+1:
    ans=min(ans,abs(count[-1]-2*count[k]))
    k+=1

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

Submission status: Wrong Answer

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
targ = sum(a) - a[0]*2

for x in a[1:n-1]:
        if abs(targ) > abs(targ-2*x):
                targ -= 2*x
        else:
                break

ans = abs(targ)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

sum_num = sum(a)
h_num = sum_num//2
s_num = a[0]
for i in range(1,N):
    if h_num <= s_num:
        break
    s_num += a[i]
a_num = sum_num-s_num
print(abs(s_num-a_num))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L_sum = a[0]

R_sum = a[N-1]

L = 0

R = N-1

while R-L != 1:
    if L_sum  < R_sum:
        while L_sum  <= R_sum and R-L != 1:
            L += 1
            L_sum += a[L]
    else:
        while R_sum <= L_sum and R-L != 1:
            R -= 1
            R_sum += a[R]
print(abs(L_sum-R_sum))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
arai = sum(a)
sunu = 0
for i in range(N-1):
    if abs(arai-sunu-2*a[i]) <= abs(arai-sunu) or i == 0:
        arai -= a[i]
        sunu += a[i]
    else:
        break
print(abs(arai-sunu))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
arai = sum(a)
sunu = 0
for i in range(N-1):
    if abs(arai-sunu-2*a[i]) < abs(arai-sunu) or i == 0:
        arai -= a[i]
        sunu += a[i]
    else:
        break
print(abs(arai-sunu))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
arai = sum(a)
sunu = 0
for i in range(N-1):
    if abs(arai-2*a[i]) < abs(arai-sunu) or i == 0:
        arai -= a[i]
        sunu += a[i]
    else:
        break
print(abs(arai-sunu))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

m = sum(a)//2
ans = 0
s = float("inf")
t = 0
for i in range(n-1):
  t += a[i]
  if  abs(m-t) <= s:
    s = abs(m-t)
    ans = i+1
  else: break

print(abs(sum(a[:ans]) - sum(a[ans:])))

Submission status: Wrong Answer

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

m = sum(a)//2
ans = 0
s = float("inf")
t = 0
for i in range(n-1):
  t += a[i]
  if  abs(m-t) <= s:
    s = abs(m-t)
    ans = i+1
  else: break

print(abs(sum(a[:ans]) - sum(a[ans:])))

Submission status: Wrong Answer

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

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

print(mn)

Submission status: Wrong Answer

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

b = sum(a)
for i in range(N-1):
    b = min(b, abs(sum(a[:i+1])-sum(a[:i:-1])))
print(b)

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]
m=a[-1]
ans=10**18
for i in range(n):
  ans=min(ans,abs(m-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]
m=a[-1]
ans=10**10
for i in range(n):
  ans=min(ans,abs(m-2*a[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
A = list(map(int,input().split()))
total = sum(A)
ACC = list(itertools.accumulate(A))

ans = 10 ** 10
for a in ACC:
  ans = min(ans,abs(total - 2 * a))
  
print(ans)

Submission status: Wrong Answer

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

ans = sum(a[1:])-a[0]
X = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

ans = sum(a[1:])-a[0]
X = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

ans = sum(a)
X = sum(a)

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

print(ans)

Submission status: Wrong Answer

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

ans = 10000000000
aa = sum(a)

for i in range(N-1):
    sum_a = sum(a[:i+1])
    sum_b = aa-sum_a
    sa = abs(sum_a-sum_b)
    if ans >= sa:
        ans = sa
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
x = 0
y = sum(A)
A.pop()
ans = 10**9

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = 10**9

for n in range(1,N):
  x = sum(A[:n])
  y = sum(A[n:])
  a = min(a,abs(x-y))

print(a)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N =ii()
    A = il()
    sm = sum(A)
    # for n in range(N-1):
    #     A[n+1] += A[n]

    ret = MAX
    for n in range(N-1):
        ret = min(ret, abs(-sm+(2*sum(A[:n]))))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N =ii()
    A = il()
    sm = sum(A)
    for n in range(N-1):
        A[n+1] = abs(A[n]) + abs(A[n+1])

    ret = MAX
    for n in range(N):
        ret = min(ret, abs(sm-(2*A[n])))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    a[i] = abs(a[i])
a = sorted(a,reverse=True)
x = a[0]
y = a[1]
for i in range(2,n):
    if x >= y:
        y += a[i]
    else:
        x += a[i]
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
x = a[0]
y = a[1]
for i in range(2,n):
    if x >= y:
        y += a[i]
    else:
        x += a[i]
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
limit = 10**9
b = 0
for i in a[:-1]:
    b += i + i
    diff = abs(total - b)
    if limit > diff:
        limit = diff
print(limit)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
snk = a[0]
ari = a[n-1]
del a[0], a[-1]

while len(a) != 0:
    if snk <= ari:
        snk += a[0]
        del a[0]
    else:
        ari += a[-1]
        del a[-1]
print(abs(snk-ari))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
snk = a[0]
arigm = a[n-1]
c = 1
if n == 2:
    print(abs(snk-arigm))
    exit()
while True:
    if snk <= arigm:
        snk += a[c]
    else:
        arigm += a[-c]
    c += 1

    if c == n:
        print(abs(snk-arigm))
        break

Submission status: Wrong Answer

Solution code:
n=int(input())

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

mi = 10**9
for i in range(1,n-1):
  su = sum(a[0:i])
  ar = sum(a[i+1:n-1])
  _mi = abs(su-ar)
  if mi > _mi:
    mi = _mi
print(mi)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(accumulate(A))
S = B[-1]

ans = float('inf')
for i in range(1, N-1):
  x = B[i]
  y = S - x
  ans = min(ans, abs(x - y))

print(ans)

Submission status: Wrong Answer

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

 
ans = min([abs(sum(A)-2*a) for a in list(accumulate(A))])
print(ans)

Submission status: Wrong Answer

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

A.sort()
if min(A)<0 and max(A)>0:
    x = [int(a) for a in A if a >0 ]
    y = [int(a) for a in A if a <0 ]
    ans = abs(sum(x)-sum(y))
else:   
    ans = min([abs(sum(A)-2*a) for a in list(accumulate(A))])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = list(map(int,input().split()))
b = a[::-1]

if len(a) == 2:
    print(abs(a[0]-a[1]))
    exit()
    
s_1 = [0]*(n+1)
s_2 = [0]*(n+1)
for i in range(n):
    s_1[i+1] = s_1[i] + a[i]
    s_2[i+1] = s_2[i] + b[i]

ans = abs(s_1[0]-s_2[-1])

for i in range(len(s_1)):
    ans = min(ans,abs(s_1[i]-s_2[len(s_2)-1-i]))
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = sum(A)
ans = 10**9
res = 0

for i in range(n-1):
    res += A[i]
    ans = min(ans, abs(total -2*res))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
from decimal import *
a= list(map(Decimal,input().split()))

s = sum(a)

ans= 10**9

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

    ans = min(ans,abs(2*subtotal - s))


print(ans)

Submission status: Wrong Answer

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

s = sum(a)

ans= 10**9

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

    ans = min(ans,abs(2*subtotal - s))


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N = int(input())
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = bisect.bisect_left(ruiseki,sum(a)//2)
print(abs(sum(a[:b+1])-sum(a[b+1:])))

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
sum_a = sum(a)
ans = 10**5
s = [0]*(n+1)
for i in range(n-1):
    s[i+1] = s[i]+a[i]
    tmptmp = sum_a-s[i+1]
    #print('tmp', tmp)
    #print('tmptmp', tmptmp)
    x = abs(s[i+1]-tmptmp)
    ans = min(ans, x)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
sum_a = sum(a)
ans = 10**5
for i in range(n-1):
    tmp = sum(a[:i+1])
    tmptmp = sum_a-tmp
    #print('tmp', tmp)
    #print('tmptmp', tmptmp)
    x = abs(tmp-tmptmp)
    ans = min(ans, x)
print(ans)

Submission status: Wrong Answer

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

i = list(itertools.accumulate(a))
total = sum(a)
ans = pow(10, 12)
for j in i:
    ans = min(abs(j - (total - j)), ans)

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

Submission status: Wrong Answer

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

i = list(itertools.accumulate(a))
total = sum(a)
ans = pow(10, 10)
for j in i:
    ans = min(abs(j - (total - j)), ans)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools
n = int(input())
a = list(map(int, input().split()))

i = list(itertools.accumulate(a))

idx = np.abs(np.asarray(i) - sum(a) / 2).argmin()
if n == 2:
    print(abs(a[0] - a[1]))
    exit()
print(abs(i[idx] - (sum(a) - i[idx])))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x==y:
  ans = 0
else:
  ans = abs(x-y)

for i in range(2,N):
  x += a[i]
  y -= a[i]
  if x==y:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = first
    del A[0]
    del A[-1]
    answers=[]
    for a in range(N - 2):
        number += A[a]
        if number >= average:
            answers.append(a)
    answer=[]
    for a in answers:
        answer.append(abs(sum(A[:a+1])-sum(A[a+1:])+first-last))
    print(min(answer))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = first
    del A[0]
    del A[-1]
    for a in range(N - 2):
        number += A[a]
        if number >= average:
            break
    a1 = abs(sum(A[:a+1]) + first - last - sum(A[a+1:]))
    print(a1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = 0
    del A[0]
    del A[-1]
    for a in range(N - 2):
        number += A[a]
        if number >= average:
            break
    a1 = abs(sum(A[:a]) + first - last - sum(A[a:]))
    print(a1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = 0
    del A[0]
    del A[-1]
    for a in range(N - 2):
        number += A[a]
        if number >= average:
            break
    a1 = abs(sum(A[:a]) + first - last - sum(A[a:]))
    a2 = abs(sum(A[:a + 1]) + first - last - sum(A[a + 1:]))
    print(min(a1, a2))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
first=A[0]
last=A[-1]
del A[0]
del A[-1]
if N==2:
    print(abs(first-last))
else:
    average = sum(A) // 2
    number = 0
    for a in range(1, N - 1):
        number += A[a]
        if number >= average:
            break
    a1 = abs(sum(A[:a]) + first - last - sum(A[a:]))
    a2 = abs(sum(A[:a + 1]) + first - last - sum(A[a + 1:]))
    print(min(a1, a2))

Submission status: Wrong Answer

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

if n == 2:
  print(abs(a[0]-a[1]))
  exit()
l = [0]*(n+1)
for i in range(1,n+1):
  l[i] = l[i-1] + a[i-1]

ans = float("INF")
for i in range(1,n):
  if abs(l[i]-abs(l[i]-l[-1])) < ans: ans = abs(l[i]-abs(l[i]-l[-1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
if N==2:
    print(abs(A[0]-A[1]))
    exit()
SUM=sum(A)
x=0
now=0
for i in range(N-1):
    now+=A[i]
    if abs(SUM-now)<abs(SUM-x):
        x=now
y=SUM-x
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
if N==2:
    print(abs(A[0]-A[1]))
    exit()
SUM=sum(A)
x=0
now=0
for i in range(N-1):
    now+=A[i]
    if abs(SUM/2-now)<abs(SUM/2-x):
        x=now
y=SUM-x
print(abs(x-y))

Submission status: Wrong Answer

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

x = sum(a)-a[0]
y = a[0]
ans = abs(x-y)
if n > 2:
  for i in range(1,n):
    x -= a[i]
    y += a[i]
    if ans > abs(x-y): ans = abs(x-y)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),key=lambda x: -abs(x))
x = 0
y = 0
countx = 0
county = 0
for i,a in enumerate(A):
    if i == N-1:
        if countx == 0:
            x += a
            break
        elif county == 0:
            y += a
            break
    if x >= y:
        if a < 0:
            x += a
            countx += 1
        else:
            y += a
            county += 1
    else:
        if a < 0:
            y += a
            county += 1
        else:
            x += a
            countx += 1
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum = sum(a)
s = [0]
d = []
q = 0
for i in range(n-1):
    q = s[i]+a[i]
    s.append(q)
    d.append(abs(sum-2*q))

print(min(d))
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
sum = sum(a)
s = [0]
d = []
q = 0
for i in range(n):
    q = s[i]+a[i]
    s.append(q)
    d.append(abs(sum-2*q))

print(min(d))

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc067/tasks/arc078_a"

def main():
    input()
    t = list(map(int, input().split()))
    if len(t) == 2:
        print(abs(t[0] - t[1]))
        exit()
    left = t[0:len(t)//2]
    right = t[len(t)//2::]
    lsum = sum(left)
    rsum = sum(right)
    trg = []
    base = 0
    all = sum(t)
    if lsum > rsum:
        trg = left[-1::-1]
        base = rsum
    elif lsum < rsum:
        trg = right
        base = lsum
    else:
        print(0)
        exit()
    trg.pop(-1)
    ans = abs(lsum - rsum)
    # print(trg, base)
    for v in trg:
        base += v
        tm = abs(all - base)
        # print(base, tm)
        if ans > abs(base-tm):
            ans = abs(base-tm)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc067/tasks/arc078_a"

def main():
    input()
    t = list(map(int, input().split()))
    if len(t) == 2:
        print(abs(t[0] - t[1]))
        exit()
    left = t[0:len(t)//2]
    right = t[len(t)//2::]
    lsum = sum(left)
    rsum = sum(right)
    trg = []
    base = 0
    all = sum(t)
    if lsum > rsum:
        trg = left[-1::-1]
        base = rsum
    elif lsum < rsum:
        trg = right
        base = lsum
    else:
        print(0)
        exit()
    trg.pop(-1)
    ans = abs(lsum - rsum)
    # print(trg, base)
    for v in trg:
        base += v
        all = abs(all - base)
        # print(base, all)
        if ans > abs(base-all):
            ans = abs(base-all)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc067/tasks/arc078_a"

def main():
    input()
    t = list(map(int, input().split()))
    if len(t) == 2:
        print(abs(t[0] - t[1]))
        exit()
    left = t[0:len(t)//2]
    right = t[len(t)//2::]
    lsum = sum(left)
    rsum = sum(right)
    trg = []
    base = 0
    all = sum(t)
    if lsum > rsum:
        trg = left[-1::]
        base = rsum
    elif lsum < rsum:
        trg = right
        base = lsum
    else:
        print(0)
        exit()
    trg.pop(-1)
    ans = abs(lsum - rsum)
    # print(trg, base)
    for v in trg:
        base += v
        all = abs(all - base)
        # print(base, all)
        if ans > abs(base-all):
            ans = abs(base-all)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    input()
    t = list(map(int, input().split()))
    if len(t) == 2:
        print(abs(t[0] - t[1]))
        exit()
    left = t[0:len(t)//2]
    right = t[len(t)//2::]
    lsum = sum(left)
    rsum = sum(right)
    trg = []
    base = 0
    all = sum(t)
    if lsum > rsum:
        trg = left[-1::]
        base = rsum
    elif lsum < rsum:
        trg = right
        base = lsum
    else:
        print(0)
        exit()
    trg.pop(-1)
    ans = abs(lsum - rsum)
    for v in trg:
        base += v
        all = all - base
        if ans > abs(base-all):
            ans = abs(base-all)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sal=sum(al)
res=10**9+1
temp=0
for i in range(0,n-1):
    temp += al[i]
    res = min(res,abs(sal/2-temp))
    print(i,res)
    if res <=0.5:
        break

print(int(res*2))

Submission status: Wrong Answer

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

sal=sum(al)
res=10**9+1
temp=0
for i in range(0,n):
    temp += al[i]
    res = min(res,abs(sal/2-temp))
    if res <=0.5:
        break

print(int(res*2))