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

x=[]
y=[]
absxy = []
for i in range(n):
  if i==0:
    continue
  temp_x = sum(a[:i])
  temp_y = sum(a[i:])
  temp_absxy = abs(temp_x - temp_y)
  
  x.append(temp_x)
  y.append(temp_y)
  absxy.append(temp_absxy)
  
min_id = 0
min_absxy = 10**9
for i in range(len(absxy)):
  if absxy[i] < min_absxy:
    min_id = i
    min_absxy = absxy[i]
    
print(min_absxy)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = sorted(list(map(int, input().split())))
a_sum = np.cumsum(a)
sunuke = 0
res = 10**9
for i in range(n-1):
  sunuke += a[-i-1]
  if(abs(sunuke-a_sum[-i-2]) < res):
    res = abs(sunuke-a_sum[-i-2])
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 1000000000
sum_ab = sum(l)
sum_a = [0] * n
sum_a[0] = l[0]
for i in range(n - 1):
    if i == 0:
        x = sum_a[0]
    else:
        x = sum_a[i - 1] + l[i]
        sum_a[i] = x
    y = sum_ab - x
    if abs(x - y) < ans:
        ans = abs(x - y)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 1000000000
# print(l)
for i in range(1, n - 1):
    # print(l[:i])
    # print(l[i:])
    sum_a = sum(l[:i])
    sum_b = sum(l[i:])
    if abs(sum_a - sum_b) < ans:
        ans = abs(sum_a - sum_b)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
x=0
y=sum(a)
prev_min=abs(x-y)
for i in range(n):
    x+=a[i]
    y-=a[i]
    if(abs(x-y)>prev_min):
        print(prev_min)
        exit()
    prev_min=abs(x-y)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

s = list(accumulate(a))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
left = a[0]
right = total - a[0]
for i in range(1, n-1):
    left_tmp = left
    right_tmp = right
    left += a[i]
    right = total - left
    if left >= total/2:
        print(min(abs(right-left), abs(right_tmp-left_tmp)))
        exit()
print(abs(right-left))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
left = a[0]
right = total - a[0]
for i in range(1, n):
    left_tmp = left
    right_tmp = right
    left += a[i]
    right = total - left
    if i == n-1:
        print(abs(right_tmp-left_tmp))
    else:
        if left >= total/2:
            print(min(abs(right-left), abs(right_tmp-left_tmp)))
            exit()

Submission status: Wrong Answer

Solution code:
import itertools

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

s = sum(a)
ac = list(itertools.accumulate(a))

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

Submission status: Wrong Answer

Solution code:
import itertools

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

s = sum(a)
ac = list(itertools.accumulate(a))

ans = 10**9
for i in range(n):
  ans = min(ans,abs(s-ac[i]*2))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
ac = 0
bc = 1
for i in range(n):
    if a <= b:
        a += l[ac]
        ac += 1
    else:
        b += l[-bc]
        bc += 1
print(abs(a-b))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
ans = 100000000000000
a = 0
b = sum(A)
for i in range(n):
  a += A[i]
  b -= A[i]
  c = abs(a-b)
  ans = min(ans, c)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), key = lambda x:abs(x), reverse = True)

x = a.pop(-1)
y = a.pop(-1)
for v in a:
    if v >= 0:
        if x <= y:
            x += v
        else:
            y += v
    else:
        if x > y:
            x += v
        else:
            y += v

print(abs(x-y))

Submission status: Wrong Answer

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

x = 0
y = 0
for v in a:
    if x <= y:
        x += v
    else:
        y += v

print(x-y)

Submission status: Wrong Answer

Solution code:
N=int(input())
import numpy as np
A=np.array(input().split(),dtype=int)
A=np.cumsum(A)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
import numpy as np
A=np.array(input().split(),dtype=int)
A=np.cumsum(A)

ans=max(abs(A))
for i in range(N-1):
  ans=min(ans,abs(A[i]-(A[len(A)-1]-A[i])))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
import numpy as np
A=np.array(input().split(),dtype=int)
A=np.cumsum(A)

ans=max(abs(A))
for i in range(N-1):
  print(i,A[i],A[len(A)-1],abs(A[i]-(A[len(A)-1]-A[i])))
  ans=min(ans,abs(A[i]-(A[len(A)-1]-A[i])))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
import numpy as np
A=np.array(input().split(),dtype=int)
A=np.cumsum(A)

ans=A.max()
for i in range(N-1):
  ans=min(ans,abs(A[i]-(A[-1]-A[i])))
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

lin = list(accumulate(li))
su = sum(li)
mi = 10**10
for i in range(n):
    mi = min(mi,abs(su-li[i]*2))
print(mi)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
a,b=0,0
for i in reversed(A):
    if a>b:b +=i
    else:a +=i
print(abs(a-b))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
dp = [0] * N
dp[0] = sum(a)
res = float("inf")
for i in range(N - 1):
  dp[i + 1] = dp[i] - a[i]
for i in range(1, N):
  res = min(abs(2 * dp[i] - dp[0]), res)
print(res)

Submission status: Wrong Answer

Solution code:
# 累積和をととっといて比較
n = int(input())
arr = list(map(int, input().split()))

ruiseki = [0 for _ in range(n)]
ruiseki[0] = arr[0]

for i in range(1, n):
    ruiseki[i] += ruiseki[i - 1] + arr[i]

inf = 10 ** 9
ans = inf

for i in range(n - 1):
    x = ruiseki[i]
    y = ruiseki[-1] - x
    ans = min(ans, abs(x - y))
print(ans)

Submission status: Wrong Answer

Solution code:
# 累積和をととっといて比較
n = int(input())
arr = list(map(int, input().split()))

ruiseki = [0 for _ in range(n)]
ruiseki[0] = arr[0]

for i in range(1, n):
    ruiseki[i] += ruiseki[i - 1] + arr[i]

inf = 10 ** 9
ans = inf

for i in range(n):
    x = ruiseki[i]
    y = ruiseki[-1] - x
    ans = min(ans, abs(x - y))
print(ans)

Submission status: Wrong Answer

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

    sm = sum(A)
    current_sm = A[0]
    ans = 10 ** 10
    for ai in A:
        current_sm += ai
        x = abs(current_sm - (sm - current_sm))
        ans = min(ans, x)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
ans = float('Inf')
for i in range(n):
    x = sum(l[:i])
    j = abs(2*x - suml)
    ans = min(ans,j)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=10**7
if n==2:
    print(abs(a[0]-a[1]))
    exit()
for i in range(n//2+1):
    x = sum(a[:i])
    y = sum(a[i:])
    qx = sum(a[-i:])
    qy = sum(a[:-i])
    xy = abs(x-y)
    qxy = abs(qx-qy)
    if ans>=xy:
        ans=xy
    if ans>=qxy:
        ans=qxy
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=10**7
if n==2:
    print(abs(a[0]-a[1]))
    exit()
for i in range(n):
    x = sum(a[:i])
    y = sum(a[i:])
    xy = abs(x-y)
    if ans>=xy:
        ans=xy
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
x = 0
y = s
ans = s
if n == 2:
    ans = abs(a[0]-a[1])
else:
    for i in range(n):
        x += a[i]
        y -= a[i]
        if i == 0 or i == n-1:
            continue
        ans = min(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
y = s
ans = s
for i in range(1, n-1):
    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()))
s = sum(a)
x = 0
y = s
ans = s
for i in range(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()))
sumA = sum(A)
wa = [0 for _ in range(N)]
wa[0] = A[0]
for i in range(1,N):
    wa[i] = wa[i-1]+A[i]
ans = 10**9
for i in range(N-1):
    x = wa[i]
    y = sumA - wa[i]
    ans = min(ans,abs(x-y))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, a: "List[int]"):
    left_sum = list(itertools.accumulate(a))
    right_sum = list(itertools.accumulate(a[::-1]))

    answer = 10**9
    for i in range(N-1):
        answer = min(answer,abs(left_sum[i]-right_sum[N-2-i]))
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
  S[i]=S[i-1]+a[i-1]
  
ans=float("Inf")
for i in range(1,N):
  tmp=abs(S[N]-S[i]*2)
  ans=min(ans,tmp)
print(S)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
S=[0]*(N+1)
for i in range(1,N+1):
  S[i]=S[i-1]+a[i-1]
  
ans=float("Inf")
for i in range(1,N):
  tmp=abs(S[N]-S[i])
  ans=min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
s=sum(l)
mini=10**9 
p=0
for i in range(n-1):
    p+=l[i]
    mini=min(mini,abs(p-(s-p)))
print(mini)

Submission status: Wrong Answer

Solution code:
N=int(input())
li=list(map(int,input().split()))
li.sort()
S=sum(li)
x=li[0]
ans=abs(S-2*x)
for n in range(1,N-1):
    x+=li[n]
    new_ans=abs(S-2*x)
    if ans>new_ans:
        ans=new_ans
print(ans)

Submission status: Wrong Answer

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

sum_v = sum(a)
min_v = 10**10
x = 0
for i in range(0,N-1):
    x += a[i]
    y = sum_v - x 
    
    min_v = min(min_v, abs(x-y))
print(min_v)

Submission status: Wrong Answer

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

min_v = 10**10
for i in range(N-1):
    x = 0
    y = 0
    x = sum(a[:i+1])
    y = sum(a[i+1:])
    min_v = min(min_v, abs(x-y))
print(min_v)

Submission status: Wrong Answer

Solution code:
a=int(input())
A = input().split()
B = [int(s) for s in A]
lnB=len(B)
XX=0
YY=0
for i in range(lnB):
    mi=max(B)
    if XX>YY:
        YY+=mi
    else:
        XX+=mi
    B.remove(mi)
    B=list(B)
p=sum(B)
ZZ=abs(XX-YY)
print(ZZ)

Submission status: Wrong Answer

Solution code:
INF = int(1e9+7)


def main():
    N, *a = map(int, open(0).read().split())
    ans = INF
    tmp = 0
    total = sum(a)
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - total))
    print(ans)
    return


main()

Submission status: Wrong Answer

Solution code:
INF = int(1e9+7)


def main():
    N, *a = map(int, open(0).read().split())
    ans = INF
    tmp = 0
    for i in range(N - 1):
        tmp += a[i]
        ans = min(ans, abs(2 * tmp - sum(a)))
    print(ans)
    return


main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0]
for i in range(N):
    B.append(B[i]+A[i])
dmin = B[N]
for i in range(1,N):
    dmin = min(dmin,abs(B[N]-2*B[i]))
print(dmin)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=[0]*n
s[0]=a[0]
for i in range(1,n):
  s[i]=s[i-1]+a[i]
m=s[n-1]
d=10**15
for i in range(n):
  d=min(d,abs(m-(2*s[i])))
print(d)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=0
b=sum(A)

temp=10**9
ans=0
for i in range(N-1):
    a+=A[i]
    b-=A[i]
    temp=min(abs(a-b),temp)

print(temp)

Submission status: Wrong Answer

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop() 
for i in range(len(I)):
  print(end, sum(I))
  minX = min(minX, abs(sum(I) - end ) )
  end += I.pop() 
  
print(minX)

Submission status: Wrong Answer

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 10000000000
start = 0
for i in range(1, len(I)):
  start += I[i-1]
  minX = min(minX, abs(start - sum(I[-i:]) ) )
  
print(minX)

Submission status: Wrong Answer

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 1000000
for i in range(1, len(I)):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
  
print(minX)

Submission status: Wrong Answer

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 1000000
for i in range(len(I)):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
print(minX)

Submission status: Wrong Answer

Solution code:
N = int(input())
I = sorted(map(int, input().split()))
minX = 1000000
for i in range(len(I)):
  minX = min(minX, abs(sum(I[:-i]) - sum(I[-i:]) ) )
  
print(minX)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans=10**9
t=sum(a)

s=0

for i in range(0,n):
#    s=sum(a[:i])
    s+=a[i]
    ans=min(ans,abs(t-2*s))
print(ans)

Submission status: Wrong Answer

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

ans=10**9
t=sum(a)

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

Submission status: Wrong Answer

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

ans=10**9

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

for i in range(n-1):
    t_ans=abs(b[i+1]-(b[-1]-b[i+1]))
    ans=min(ans,t_ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 10 ** 9
a = 0; b = sum(A)
for i in range(N-1):
  a += A[i]; b -= A[i]
  ans = min(ans, abs(a - b))
print (ans)

Submission status: Wrong Answer

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

cnt=A[1]
ans=10**10
sum_A=sum(A)
for a in A[1:N]:
    ans=min(ans,abs(sum_A-cnt*2))
    cnt+=a

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r.append(acu_r[-1] + A[i])
#print(acu)
#print(acu_r)
INF = 10**9
ans = INF
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[N - (i + 2)]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
acu = []
acu.append(A[0])
acu_r = []
acu_r.append(A[-1])
for i in range(1,N-1):
  acu.append(acu[-1] + A[i])
for i in range(N-2,0,-1):
  acu_r.append(acu_r[-1] + A[i])
acu_r.sort(reverse = True)
INF = 10**9
ans = INF
for i in range(N-1):
  ans = min(ans,abs(acu[i] - acu_r[i]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
min_abs = 1000000000000000000000000
for i in range(1, n):
  A[i] += A[i-1]

for i in range(n):
  abs_val = abs(A[n-1] - A[i] * 2)
  min_abs = min(min_abs, abs_val)
print(min_abs)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
s = sum(a)
z = 10**10

for i in range(N-1):
  s = a[i+1]-a[i]
  z = min(z,abs(s))

print(z)

Submission status: Wrong Answer

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

for i in range(N):
  z = min(z,abs(sum(a[:i])-sum(a[i:])))

print(z)

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
a=[int(i) for i in input().split()]
card=sum(a)
snuke=0
ans=10**10
for i in range(n):
    snuke+=a[i]
    ans=min(ans,abs(snuke-(card-snuke)))
print(ans)

Submission status: Wrong Answer

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

for i in range(1,N):
  S.append(S[i-1]+C[i])
#print(S)

sc=sum(C)
#print(sc)
for i,s in enumerate(S):
  if s>sc//2:
    if i>0:
      print(min(abs(sc-2*S[i]),abs(sc-2*S[i-1])))
    else:
      print(abs(sc-2*S[i]))
    exit()

Submission status: Wrong Answer

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

M=sum(A)
x0=0
D=float('inf')
if N<=2:
    print(abs(A[0]-A[1]))
else:
    for i in range(N):
        x0+=A[i]
        D=min(D,abs(M-2*x0))
    print(D)

Submission status: Wrong Answer

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

M=sum(A)
D=[]
x0=0
if N<=2:
    print(abs(A[0]-A[1]))
else:
    for i in range(N):
        x0+=A[i]
        D.append(abs(M-2*x0))
    print(min(D))

Submission status: Wrong Answer

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

M=sum(A)
D=[]
x0=0
if N<=2:
    print(abs(A[0]-A[1]))
else:
    for i in range(N):
        x0+=A[i]
        print(x0)
        D.append(abs(M-2*x0))
    print(min(D))

Submission status: Wrong Answer

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

M=sum(A)
D=[]
x0=0
for i in range(N):
    x0+=A[i]
    D.append(abs(M-2*x0))
print(min(D))

Submission status: Wrong Answer

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

ans = float('inf')
s = sum(A)

x = A[0]
ans = min(ans, abs(2*A[0]-s))

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

print(ans)

Submission status: Wrong Answer

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

ans = float('inf')
s = sum(A)
x = A[0]

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

print(ans)

Submission status: Wrong Answer

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

ans = float('inf')
s = sum(A)
x = 0

for i in range(N):
    x += A[i]
    y = s - x
    d = abs(x-y)
    ans = min(ans, d)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
total = sum(li)

sum_ = 0
min_ = float('inf')
for i in range(n):
    sum_ += li[i]
    diff = abs(total - 2*sum_)
    if diff < min_:
        min_ = diff
print(min_)

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

ma = s[-1]

ans = 10 ** 9

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

print(ans)

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

s = s[1:]

ma = s[-1]

ans = 10 ** 18


for i in s:
    ans = min(ans, abs(ma-2*i))

print(ans)

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

s = s[1:]

ma = s[-1]

ans = 10 ** 18


for i in s:
    ans = min(ans, abs((ma - i) - i))

print(ans)

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

s = s[1:]

ma = s[-1]

ans = 10 ** 9


for i in s:
    ans = min(ans, abs((ma - i) - i))

print(ans)

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

s = s[1:]

x = s[-1] / 2

temp = 10 ** 9
ind = 0

for i in range(len(s)):
    if abs(x - s[i]) < temp:
        temp = abs(x - s[i])
        ind = i

print(abs((s[-1] - s[ind]) - s[ind]))

Submission status: Wrong Answer

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

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

s = [0]

for i in range(n):
    s.append(s[-1]+a[i])

x = s[-1] / 2

temp = 10 ** 9
ind = 0

for i in range(len(s)):
    if abs(x - s[i]) < temp:
        temp = abs(x - s[i])
        ind = i

print(abs((s[-1] - s[ind]) - s[ind]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 0
x = A[0]
y = A[-1]
x_cnt = 1
y_cnt = -2
for _ in range(N - 2):
  if x - y <= 0:
    x += A[x_cnt]
    x_cnt += 1
  else:
    y += A[y_cnt]
    y_cnt -= 1
print(abs(x - y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [0] * N
x = sum(A)
y = 0
ret = 10 ** 9 + 7
for i, a in enumerate(A[:-1]):
  y += a
  x -= a
  ret = min(ret, abs(x - y))
print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
sum_a = sum(a)
acc = list(itertools.accumulate(a))
ans = mod
for i in range(n-1):
    tmp = abs(acc[i] - (acc[-1] - acc[i]))
    ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 10**9
lcums = np.cumsum(data)
rcums = list(reversed(np.cumsum(list(reversed(data)))))
for i in range(0,N-1):
    ans = min(ans,abs(lcums[i]-rcums[i+1]))
print(ans)

Submission status: Wrong Answer

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

l,r=[sum(A[:-1])],[A[-1]]
for i in range(1,n):
  l.append(l[-1]-A[i])
  r.append(r[-1]+A[i])
ans=float('inf')
for i in range(n):
  ans=min(ans,abs(l[i]-r[i]))
print(ans)

Submission status: Wrong Answer

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

l,r=[sum(A[:-1])],[A[-1]]
for i in range(1,n-1):
  l.append(l[-1]-A[i])
  r.append(r[-1]+A[i])
ans=float('inf')
for i in range(n-1):
  ans=min(ans,abs(l[i]-r[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N):
  x = x + l[i]
  ans = min(ans, abs(x - (S - x)))
  print(ans)
 
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
ans = 100000000000000
x = 0
S = sum(l)
for i in range(N):
  x = x + l[i]
  ans = min(ans, abs(x - (S - x)))
 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = 1000000000
s = sum(l)
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  #dif = abs(sum(l[:i])-sum(l[i:]))
  dif = abs(s - 2*sum(l[i:]))
  if dif < ans:
    ans = dif
  else:
    continue
 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = 10000000
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  #dif = abs(sum(l[:i])-sum(l[i:]))
  dif = abs(sum(l) - 2*sum(l[i:]))
  if dif < ans:
    ans = dif
  else:
    continue

print(ans)

Submission status: Wrong Answer

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

min_sum = 10**9+1

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
su=sum(a)
mini=float('inf')
check=0
for i in a:
    check+=i
    if mini>abs(su/2-check):
        ans=abs(su-check-check)
        mini=su/2-check
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
x = A[0]
y = sum(A[1:])
ans = float('inf')
if N == 2:
    print(abs(A[0]-A[1]))
for i in range(1,N-1):
    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 = a[0]
y = sum(a[1:])
mn = abs(x - y)
i = 1
while x < y and i < n - 1:
    mn = x - y
    d = a[i]
    x += d
    y -= d
    i += 1 
print(min(abs(x - y), abs(mn)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = a[0]
y = sum(a[1:])
mn = abs(x - y)
i = 1
while x < y and i < n - 1:
    mn = x - y
    d = a[i]
    x += d
    y -= d
print(min(abs(x - y), abs(mn)))

Submission status: Wrong Answer

Solution code:
# C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)//2
for i in range(1,N):
    if sum_s < tmp:
        sum_s += a[i]
        if sum_s > tmp:
            sum_s -= a[i]
            break
    else:
        break
sum_a = sum(a) - sum_s
ans = abs(sum_s - sum_a)
print(ans)

Submission status: Wrong Answer

Solution code:
# C - Splitting Pile
N = int(input())
a = list(map(int, input().split()))
sum_s = a[0]
tmp = sum(a)//2
for i in range(1,N):
    if sum_s < tmp:
        sum_s += a[i]
    else:
        break
sum_a = sum(a) - sum_s
ans = abs(sum_s - sum_a)
print(ans)

Submission status: Wrong Answer

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

#累積和のリストを作りますが最後の要素は使いません
for i in range(N-1):
  s += A[i]
  S.append(s)

s = sum(A) #再利用（よくない）

for i in range(N-1):
  S[i] = abs(S[i] - s)
print(min(S))

Submission status: Wrong Answer

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