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())
A = list(map(int,input().split()))
S1 = A[0]
S2 = sum(A)-A[0]
B = [S1-S2]

for i in range(N-2):
  S1 += A[i+1]
  S2 -= A[i+1]
  B.append(abs(S1-S2))

print(min(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
alst = list(map(int, input().split()))
total = sum(alst)
x = alst[0]
ans = abs(total - 2 * x)
for a in alst[1:-1]:
  x += a
  dif = total - 2 * x
  ans = min(abs(dif), ans)
  if dif >= 0:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
alst = list(map(int, input().split()))
total = sum(alst)
x = alst[0]
ans = abs(total - 2 * x)
for a in alst[1:-1]:
  x += a
  dif = total - 2 * x
  ans = min(abs(dif), ans)
  if dif <= 0:
    break
print(ans)

Submission status: Wrong Answer

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

ans = []

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

for i in range(n):
  tmp = abs(a2[-1] - 2*a2[i])
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

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

ans = []

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

for i in range(n):
  tmp = abs(a2[i] - (a2[-1] - a2[i]))
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

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

ans = []

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

for i in range(n):
  tmp = abs(a2[i] - (a2[-1] - a2[i]))
  ans.append(tmp)
print(min(ans))
print(ans)

Submission status: Wrong Answer

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

ans = []

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

for i in range(n):
  tmp = abs(a2[i] - abs(a2[-1] - a2[i]))
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

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

ans = []

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

for i in range(n):
  tmp = abs(a2[i] - abs(a2[-1] - abs(a2[i])))
  ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = sum(a)
data = [a[0]]
m = abs(a[0] - a[-1])

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

for i in range(0, N - 1):
    if abs(s - 2 * data[i]) < m:
        m = abs(s - 2 * data[i])

print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=[a[0]]
y=[]
X=a[0]
Y=0
s=sum(a)
if 2*a[0]-s>0:
  ans=float('inf')
  for i in range(n):
    ans=min(ans,abs(s-2*a[i]))
  print(ans)
else:
  for i in range(1,n):
    if a[i]>=0 and X-Y>0:
      Y+=a[i]
      y.append(a[i])
    elif a[i]>=0 and X-Y<=0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y>0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y<=0:
      Y+=a[i]
      y.append(a[i])
  print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
if 2*a[0]-s>0:
  ans=float('inf')
  for i in range(n):
    if a[i]>=0:
      ans=min(ans,abs(s-2*a[i]))
    else:
      ans=min(ans,abs(s-2*a[i]))
  print(ans)
else:
  x=[a[0]]
  y=[]
  X=a[0]
  Y=0
  for i in range(1,n):
    if a[i]>=0 and X-Y>0:
      Y+=a[i]
      y.append(a[i])
    elif a[i]>=0 and X-Y<=0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y>0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y<=0:
      Y+=a[i]
      y.append(a[i])
  print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
ans=float('inf')
res=0
for i in range(n-1):
  res+=a[i]
  ans=min(ans,abs(s-2*res))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
if 2*a[0]-s>0:
  ans=float('inf')
  for i in range(n):
    if a[i]>=0:
      ans=min(ans,abs(s-2*a[i]))
    else:
      ans=min(ans,abs(s-2*a[i]))
  print(ans)
else:
  x=[a[0]]
  y=[]
  X=a[0]
  Y=0
  for i in range(1,n):
    if a[i]>=0 and X-Y>0:
      Y+=a[i]
      y.append(a[i])
    elif a[i]>=0 and X-Y<=0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y>0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y<=0:
      Y+=a[i]
      y.append(a[i])
  print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x=[a[0]]
y=[]
X=a[0]
Y=0
s=sum(a)
if 2*a[0]-s>0:
  ans=float('inf')
  for i in range(n):
    ans=min(ans,abs(s-2*a[i]))
  print(ans)
else:
  for i in range(1,n):
    if a[i]>=0 and X-Y>0:
      Y+=a[i]
      y.append(a[i])
    elif a[i]>=0 and X-Y<=0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y>0:
      X+=a[i]
      x.append(a[i])
    elif a[i]<0 and X-Y<=0:
      Y+=a[i]
      y.append(a[i])
  print(abs(X-Y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    sum_a = sum(a)
    min_diff = 1000000000000000000000

    sum_x = 0
    for i in range(0, n-1):
        sum_x = sum_x + a[i]
        diff = abs(sum_a - 2*sum_x)
        if min_diff > diff:
            min_diff = diff

    print(min_diff)

    '''
    half = sum_a // 2

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

    print(min_diff)
    '''

# 真ん中を分けるカードの差がわかればよい


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    sum_a = sum(a)
    min_diff = 1000000000000000000000

    for i in range(1, n):
        sum_x = sum(a[:i])
        diff = abs(sum_a - 2*sum_x)
        if min_diff > diff:
            min_diff = diff

    print(min_diff)

    '''
    half = sum_a // 2

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

    print(min_diff)
    '''

# 真ん中を分けるカードの差がわかればよい


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    sum_a = sum(a)
    half = sum_a // 2

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

    print(min_diff)

# 真ん中を分けるカードの差がわかればよい


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    sum_a = sum(a)
    half = sum_a // 2

    diff = []
    for i in range(n-1):
        diff.append(a[i+1] - a[i])
    min_diff = min(diff)

    print(min_diff)

# 真ん中を分けるカードの差がわかればよい


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
for i in range(n):
  ans=abs(ans-a[i])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=sum(a)
t=0
for i in range(n):
  if s-a[t]>=a[t]:
    s-=2*a[t]
  t+=1
print(s)

Submission status: Wrong Answer

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    m=min(abs(t),m)
print(m)

Submission status: Wrong Answer

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    m=min(t,m)
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
p=0
q=0
t=0
for i in range(n):
  if t%2==0:
    p+=a[i]
    t+=i+1
  else:
    q+=a[i]
    t+=i+1
print(abs(p-q))

Submission status: Wrong Answer

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    if t<=0 :
        if i==0:
            print(abs(t))
            flag = 1
            break
        else:
            print(min(abs(t+2*a[i]),abs(t)))
            flag=1
            break
if flag==0:
    print(t)

Submission status: Wrong Answer

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

t=sum(a)
m=10**9
flag=0
for i in range(len(a)-1):
    t-=2*a[i]
    if t<=0 :
        if i==0:
            print(abs(t))
            flag = 1
            break
        else:
            print(min(abs(t+2*a[i]),abs(t)))
            flag=1
            break
else:
    print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
nums = []
total = 0
for num in a:
    total += num
    nums.append(total)
minVal = 10 ** 9 + 1
for i in range(n - 1):
    sub = total - nums[i]
    minVal = min(abs(sub - nums[i]), minVal)
print(minVal)

Submission status: Wrong Answer

Solution code:
# C - Splitting Pile
N = int(input())
A = list(map(int,input().split()))

s = [0]*(N+1)
for i in range(N-1):
    s[i+1] = s[i] + A[i]
print(s)

ans = 10**10
for i in range(1,N):
    diff = abs((s[N-1] + A[-1] - s[i]) - s[i])
    ans = min(ans,diff)
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    asum[i+1] = asum[i] + a[i]

ans = 10**9
for i in range(1,n):
    snu = asum[i]
    arai = asum[-1] - asum[i]
    ans_ = abs(snu - arai)
    if ans >ans_:
        ans = ans_
        
print(ans)

Submission status: Wrong Answer

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

sm = sum(a)
acc = [0]
for i in range(n):
  acc.append(acc[-1] + a[i])

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

Submission status: Wrong Answer

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

a = sorted(a)
x = [0]
y = []
y.append(a.pop())

while a:
    if sum(x) <= sum(y):
        x.append(a.pop(0))
    else:
        y.append(a.pop())

print(abs(sum(x)-sum(y)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
import math
sunuke = 0
kuma = sum(a)

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

for i in range(n):
    sunuke += a[i]
    kuma -= a[i]
    if abs(sunuke-kuma) > memo:
        ans = memo
        break
    else:
        memo = abs(sunuke-kuma)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=float("inf")
x=0
b=sum(a)
for i in range(n):
    x+=a[1]
    if i+1<n:
        ans=min(ans,abs(b-2*x))    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans,res=0,0
b=sum(a)
for i in range(n):
    ans+=a[i]
    res=a[i]
    if ans>b-ans:
        break
if ans==res:
    print(abs(ans-(b-ans)))
else:
    print(min(abs(ans-(b-ans)),abs(ans-res-(b-(ans-res)))))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans,res=0,0
for i in range(n):
    ans+=a[i]
    res=a[i]
    if ans>sum(a)-ans:
        break
if ans==res:
    print(abs(ans-(sum(a)-ans)))
else:
    print(min(abs(ans-(sum(a)-ans)),abs(ans-res-(sum(a)-(ans-res)))))

Submission status: Wrong Answer

Solution code:
import math

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

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

P = [0]
for a in A:
    P.append(P[-1] + a)

Q = [P[-1]-c for c in P]

ans = math.inf
for x, y in zip(P, Q):
    ans = min(ans, abs(x-y))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

cum_sum = [0]
for a in A:
    cum_sum.append(cum_sum[-1]+a)

ans = math.inf
for x in cum_sum[1:]:
    y = cum_sum[-1] - x
    ans = min(ans, abs(x-y))
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()

cum_sum = [0]
for a in A:
    cum_sum.append(cum_sum[-1]+a)

ans = 10**9+1
for x in cum_sum[1:]:
    y = cum_sum[-1] - x
    ans = min(ans, abs(x-y))
print(ans)

Submission status: Wrong Answer

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

snk = a[0]
s = sum(a)
x = s / 2
for i in range(1, n - 1):
    snk += a[i]
    if snk >= x:
        break

ari = s - snk
p = abs(snk - ari)
if n > 2:
    snk -= a[i]
ari = s - snk
q = abs(snk - ari)
print(min(p, q))

Submission status: Wrong Answer

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

s = sum(a)
x = s / 2
count = 0
for i in range(n):
    count += a[i]
    if count >= x:
        break
p = abs(count - (s - count))
if i > 1:
    count -= a[i]
q = abs(count - (s - count))
print(min(p, q))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input());a=list(map(int,input().split()));f,b,c=0,sum(a),float('inf')
for i in range(n):
  f,b=f+a[i],b-a[i]
  c=min(c,abs(f-b))
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

ans = 1001001000
l = a[0]
r = sum(a)-l

for i in range(n):
    if abs(l-r) <= ans:
        ans = abs(l-r)
    if i == n-1:
        break
    l += a[i]
    r -= a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

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

ans = 1001001000
l = a[0]
r = sum(a)-l

for i in range(1, n): 
    if abs(l-r) <= ans:
        ans = abs(l-r)
    l += a[i]
    r -= a[i]

print(ans)

Submission status: Wrong Answer

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

S = sum(A)

snk = 0
arigm = S

ans = 1e20

for i in range(1,N):
  snk += A[i]
  arigm -= A[i]
  #print(snk,arigm)
  ans = min(abs(snk-arigm),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A.sort(reverse=True)
total = sum(A)
x, y = A[1], A[0]

# ans = abs(total)
cnt = 0
ans = 0
ans = abs(x - y)
# print(ans)
for i, a in enumerate(A):
    if i == 0 or i == 1:
        continue
    else:
        if a >= 0:
            if x <= y:
                nx = x + a
                ny = y
                # print(a)
            else:
                nx = x
                ny = y + a
                # print(a)
            # print("nx, ny:", nx, ny)
        else:
            if x > y:
                nx = x + a
                ny = y 
            else:
                nx = x
                ny = y + a
        # print(nx, ny, x, y)
        if abs(nx - ny) < abs(x - y):
            ans = abs(nx - ny)
            x = nx
            y = ny
        else:
            ans = abs(x - y)
            x = nx
            y = ny
print(ans)
            
    





#     cx = x
#     cy = y
#     nx = x + a
#     ny = y - a
#     if abs(nx - ny) < abs(x - y):
#         x = nx
#         y = ny
#         ans = abs(nx - ny)
#         cnt += 1
# if cnt == 0:
#     x = x + A[0]
#     y = y - A[0]
#     ans = abs(x - y)

# print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

A.sort(reverse=True)
total = sum(A)
# ans = abs(total)
x, y = 0, sum(A)
ans = abs(total)
# x = 0
# y = 0
# z = 0
cnt = 0
for i, a in enumerate(A):
    # if i == 0:
    #     x += a
    #     y -= a

    # else:
    cx = x
    cy = y
    nx = x + a
    ny = y - a
    if abs(nx - ny) < abs(x - y):
        x = nx
        y = ny
        ans = abs(nx - ny)
        cnt += 1
if cnt == 0:
    x = x + A[0]
    y = y - A[0]
    ans = abs(x - y)

print(ans)

Submission status: Wrong Answer

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

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

for i in range(1, n-1):
    snuke += 2 * a[i]
    if abs(snuke - s) < ans:
        ans = abs(snuke - s)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
l,r=a.pop(0),sum(a)
ans=10**9
for i in a:
    ans=min(ans,abs(l-r))
    l,r=l+i,r-i
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
l,r=a.pop(0),sum(a)
ans=10**9
for i in a:
    ans=min(ans,abs(l-r))
    l,r=i,r-i
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
l,r=0,sum(a)
ans=10**9
for i in a:
    l,r=i,r-i
    ans=min(ans,abs(l-r))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
sa = a[:]
for i in range(N-1):
  sa[i+1] += a[i]

diff = float('inf')
for i in range(N-1):
  if abs(sa[i] - (sa[-1] - sa[i])) < diff:
    diff = abs(sa[i] - (sa[-1] - sa[i]))

print(diff)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
INF = float('inf')
N = int(input())
A = [int(x) for x in input().split()]

cumA = list(accumulate(A))
ans = INF
for i in range(N - 1):
    x = cumA[i]
    y = cumA[N - 1] - cumA[i]
    ans = min(ans, abs(x - y))
    if x > y: break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
S=sum(A)
x=A[0]
y=A[-1]
xy_min=abs(x-y)
for i in range(1,n-1):
  x+=A[i]
  y=S-x
  xy=abs(x-y)
  if xy<xy_min:
    xy_min=xy
print(xy_min)

Submission status: Wrong Answer

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

li = [0]

for i in range(n):
    li.append(li[i]+ L[i])
print(li)
sumL = sum(L)
#print(sumL)
ans = 10**10
for i in range(1,n):
    diff = abs(li[i] - (sumL - li[i]))
    #print(diff,li[i],sumL-li[i])
    ans = min(ans,diff)        
print(ans)

Submission status: Wrong Answer

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

sunuke=0
araiguma=0

for i in range(N):
    if abs(sunuke)<=abs(araiguma):
        sunuke=sunuke+a[0]
        a.pop(0)
    else:
        araiguma=araiguma+a[-1]
        a.pop()

print(abs(sunuke-araiguma))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N = int(input())
A = tuple(accumulate(map(int, input().split())))
x = A[-1]
y = A[0]
ans = abs(x - y - y)
for a in A:
    ans = min(ans, abs(x - a - a))
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    acc_A = []
    acc = 0
    for a in A:
        acc += a
        acc_A.append(acc)

    minv = 1001001001
    for i in range(0, N-1):
        minv = min(abs(acc_A[i]-(acc_A[-1]-acc_A[i])), minv)
    print(minv)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    acc_A = []
    acc = 0
    for a in A:
        acc += a
        acc_A.append(acc)

    minv = 1001001001
    for c in acc_A:
        minv = min(abs(c-(acc_A[-1]-c)), minv)
    print(minv)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = list(map(int, input().split()))
a = list(np.cumsum(A))
r = sum(A)-A[0]
l = A[0]
ans = abs(r-l)
for i in range(1,len(a)):
    r -= a[i]
    l += a[i]
    ans = min(ans, abs(l-r))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = list(accumulate(A))
    minimum = 10**18
    for c in S:
        if c == S[-1]: continue
        minimum = min(minimum, abs(2 * c - S[-1]))
    print(minimum)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

f=0
b=sum(a)
m=2*10**5+1
for i in range(n-1):
    f+=a[i]
    b-=a[i]
    m=min(m,abs(f-b))
print(m)

Submission status: Wrong Answer

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

f=0
b=sum(a)
m=2*10**5+1
for i in range(n-1):
    f+=a[i]
    b-=a[i]
    print(f,b)
    m=min(m,abs(f-b))
print(m)

Submission status: Wrong Answer

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

f=0
b=sum(a)
m=abs(b)
for x in a:
    f+=x
    b-=x
    m=min(m,abs(f-b))
print(m)

Submission status: Wrong Answer

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

f=0
b=sum(a)
m=b
for x in a:
    f+=x
    b-=x
    m=min(m,abs(f-b))
print(m)

Submission status: Wrong Answer

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

m=2*10*9+1

for x in range(1,n):
    m=min(m,abs(sum(a[:x])-sum(a[x:])))
print(m)

Submission status: Wrong Answer

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

ans=10**9+10
s=sum(a)
now=0
snuke=0
for i in range(N-1):
    snuke+=a[i]
    now=s-2*snuke
    ans=min(abs(now),ans)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

m = 10**9
x = 0
X = sum(a)

for i in range(n):
    x += a[i]
    if i+1 < n:
        m = min(m, abs(X-2*x))

print(m)

Submission status: Wrong Answer

Solution code:
import math

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

m = 10**9
x = 0

for i in range(n):
    x += a[i]
    if i+1 < n:
        m = min(m, abs(sum(a)-2*x))

print(m)

Submission status: Wrong Answer

Solution code:
import math

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

m = 10**9

for i in range(1, n):
    m = min(m, abs(sum(a[:i]) - sum(a[i:])))

print(m)

Submission status: Wrong Answer

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

minint = 10**9

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

else:
    s1 = s1 = sum(a[0:1])
    s2 = sum(a[1: N])
    for i in range(1, N):
        s1 += a[i]
        s2 -= a[i]
        
        minint = min(minint, abs(s1 - s2))

    print(minint)

Submission status: Wrong Answer

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

asum = sum(a)
aave = asum // 2

s1 = 0
s2 = 0

i = 0

if N != 2:
    while s1 <= aave and i < N:
        s2 = s1
        s1 += a[i]
        i += 1

    if i == N:
        print(min(abs(s[0: N - 2] - s[N - 1]), abs(s[0] - s[1: N - 1])))
        exit()

    print(min(abs(asum - s1 * 2), abs(asum - s2 * 2)))

else:
    print(abs(a[0] - a[1]))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

B = list(accumulate(A))
p = B[-1]
ans = 10**9
for i in range(N-1):
    ans = min(ans,abs(p-2*B[i]))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(T) for T in input().split()]
L = [0]*(N+1)
R = [sum(A)]*(N+1)
for T in range(0,N):
    L[T+1] = L[T]+A[T]
    R[T+1] = R[T]-A[T]
MIN = 10**9
for T in range(1,N):
    if abs(L[T]-R[T])<MIN:
        MIN = abs(L[T]-R[T])
print(MIN)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

input()
(*a,) = map(int, input().split())
print(min(abs(sum(a) - x - y) for (x, y) in zip(a, accumulate(a))))

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
INF = 10 * 18
N = int(input())
A = list(map(int, input().split()))
res = INF
t = sum(A)
s = 0
for a in A[:-1]:
    s += a
    res = min(res, abs(t - s - s))
print(res)

Submission status: Wrong Answer

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

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)

Submission status: Wrong Answer

Solution code:
# C - pushpush
N = int(input())
a = list(map(int,input().split()))

lst = [0]*(N-1)
x = a[0]
y = sum(a)-a[0]
lst[0] = abs(x-y)

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

ans = min(lst)
print(ans)

Submission status: Wrong Answer

Solution code:
# C - pushpush
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)

S = sum(a)
lst = [0]*N

x = 0
y = 0

for i in range(N):
    x = sum(a[0:i])
    y = S - x
    lst[i] = abs(x-y)
lst.pop(0)

ans = min(lst)
print(ans)

Submission status: Wrong Answer

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

a.sort()

ans = 10**9+1
for i in range(1,N):
    min_a = abs(sum(a[:i]) - sum(a[i:]))
    if ans > min_a:
        ans = min_a

print(ans)

Submission status: Wrong Answer

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

a.sort()

ans = 10**9+1
for i in range(1,N+1):
    min_a = abs(sum(a[:i]) - sum(a[i:]))
    if ans > min_a:
        ans = min_a

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)
tot = sum(A)
if A[0]>tot//2:
    ans = 2*A[0]-tot
    for i in range(1,N):
        ans = min(ans,abs(2*A[i]-tot))
else:
    cnt = A[0]
    for i in range(1,N):
        if cnt+A[i]>tot//2:
            ind = i
            break
        else:
            cnt += A[i]
    ans = abs(2*cnt-tot)
    for i in range(ind,N):
        ans = min(ans,abs(2*(cnt+A[i])-tot))
print(ans)

Submission status: Wrong Answer

Solution code:
N,*A = map(int, open(0).read().split())

S = sum(A)
k = 0
m = 10**18

for i,a in enumerate(A):
    if i == N - 1: break
    k += a
    d = abs(S - 2*k)
    if d < m:
        m = d
    else:
        break

print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
S = [0]
for i in range(N):
  temp = S[-1]+A[i]
  S.append(temp)
total = sum(A)
target = total//2

ok = 1
ng = N
while abs(ng-ok) > 1:
  mid = (ok+ng)//2
  if S[mid] <= target:
    ok = mid
  else:
    ng = mid
kouho = abs(total-S[ok]*2)
if ok+1 < N:
  kouho2 = abs(total-S[ok+1]*2)
  ans = min(kouho,kouho2)
else:
  ans = kouho
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)