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()))
S=sum(a)
s=2*a[0]
d=abs(a[1]-a[0])
for i in range(1,N-1):
    s+=2*a[i]
    if s>S:
        d=s-S
        s=S-s+2*a[i]
        break
print(min(s,d))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc067/tasks/arc078_a
# C - Splitting Pile
import math

n = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = sorted(a_list, reverse=True)
# print(a_list)
x = math.ceil(sum(a_list) / 2)

# print(x)
total = 0
# work_list = []

for a in a_list:
    if total + a <= x:
        total += a
        # work_list.append(a)
# print(work_list)
b = sum(a_list) - total
ans = abs(b - total)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc067/tasks/arc078_a
# C - Splitting Pile
import math

n = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = sorted(a_list, reverse=True)

x = math.ceil(sum(a_list) / 2)
total = 0

for a in a_list:
    if total + a < x:
        total += a

b = sum(a_list) - total
ans = abs(b - total)
print(ans)

Submission status: Wrong Answer

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

    filled = [0]*(n+1)
    ans = []
    for i in range(n-1, -1, -1):
        if sum(filled[::i+1][1:]) % 2 != A[i]:
            filled[i+1] = 1
            ans.append(i+1)
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S = sum(A)
ans = 10**11

for i in range(N-1):
    X[i+1] = X[i] + A[i]
    t = abs(X[i]+X[i]-S)
    ans = min(ans,t)

print(ans)

Submission status: Wrong Answer

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

S = sum(A)
ans = 10**11

for i in range(1,N):
    X[i] += A[i]
    t = abs(X[i]+X[i]-S)
    ans = min(ans,t)

print(ans)

Submission status: Wrong Answer

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

S = sum(A)
ans = 10**11

for i in range(1,N):
    X[i] = X[i-1] + A[i]
    t = abs(X[i]+X[i]-S)
    ans = min(ans,t)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
an = [int(x) for x in input().split()]
an_sum = sum(an)
x_sum = 0
ans = 10e10
for x in range(0,n):
    x_sum += an[x]
    ans = min(ans, abs(an_sum-2*x_sum))
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


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


cumsum = []
ret = 0


for i in (nums):
    ret += i
    cumsum.append(ret)


s = cumsum[-1]


min_val = float('inf')


for i in range(len(cumsum)-1):
    if (cumsum[i] >= s/2 and s/2 >= cumsum[i+1]) or (cumsum[i] <= s/2 and s/2 <= cumsum[i+1]):
        min_val = min(abs((s - cumsum[i]) - cumsum[i]), min_val)
        if i != len(cumsum)-2:
            min_val = min(abs((s - cumsum[i+1]) - cumsum[i+1]), min_val)



print(min_val)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    if i < n - 1:
        print("DO", total, s)
        ma = min(ma, abs(total - s + total))
print(ma)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
total = 0
ma = 10 ** 20
for i in range(n):
    total += a[i]
    print(total, s)
    if i < n - 1:
        print("DO", total, s)
        ma = min(ma, abs(total - s + total))
print(ma)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(N: int, a: "List[int]"):
    x = [0] * (N+1)
    for i in range(1,N+1):
        x[i] = a[i-1]+x[i-1]

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

    print(m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    # sum(a)/2を計算していて、近い場所を二部探索
    x = [0] * (N)
    for i in range(1,N):
        x[i] = a[i-1]+x[i-1]

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

    print(m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    # sum(a)/2を計算していて、近い場所を二部探索
    x = [0] * (N+1)
    for i in range(1,N):
        x[i] = a[i-1]+x[i-1]

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

    print(m)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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()))

X, Y = [0]*N, [0]*N
X[0] = a[0]
Y[-1] = a[-1]

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

ans = 9999999

for i in range(N-1):
    ans = min(abs(X[i]-Y[i+1]),ans)
print(ans)

Submission status: Wrong Answer

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


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

ret = 10**9+1
for i in range(1, N):
    x = cum[i]
    y = cum[-1] - x
    if abs(x-y) < ret:
        ret = abs(x-y)
    
print(ret)

Submission status: Wrong Answer

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


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

ret = 10**9
for i in range(1, N):
    x = cum[i]
    y = cum[-1] - x
    if abs(x-y) < ret:
        ret = abs(x-y)
    
print(ret)

Submission status: Wrong Answer

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


def solve(N: int, a: "List[int]"):
    S = sum(a)
    L = [a[0]]
    for i in range(1, N):
        L.append(L[-1] + a[i])
    mx = 1e9
    for i in range(0, N-1):
        d = abs((S - L[i]) - L[i])
        mx = min(d, mx)
    print(mx)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
sum_an = sum(an)
from itertools import accumulate
an_acc = accumulate(an)
print(min(list(map(lambda x : abs(sum_an-x*2),an_acc))))

Submission status: Wrong Answer

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

S = sum(A)

k = 0
ans = int(1E9)
for i, a in enumerate(A):
    if i == N-1:
        break
    k += a
    ans = min(ans, abs(2*k-S))

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in range(N-1):
        sum_first += i
        if min_diff > abs(sum_a - 2 * sum_first):
            min_diff = abs(sum_a - 2 * sum_first)

    print(min_diff)

main()

Submission status: Wrong Answer

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

    sum_a = sum(a)
    min_diff = float('inf')
    sum_first = 0
    for i in a:
        if a[N-1] == i:
            break
        sum_first += i
        if min_diff > abs(sum_a-2 * sum_first):
            min_diff = abs(sum_a-2 * sum_first)

    print(min_diff)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
ans = 10**18
for i in a:
  x += i
  y -= i
  tmp = abs(x-y)
  ans = min(tmp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
x = 0
y = 0
fx,fy=0,0
for i in a:
  if i >= 0:
    if x >= y:
      y += i
      fy = 1
    else:
      x += i
      fx=1
  else:
    if x >= y:
      x += i
      fx=1
    else:
      y += i
      fy=1
if fx == 0 or fy == 0:
  print(abs(x-y)+abs(a[-1]*2))
else:
  print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
x = a.pop(a.index(max(a)))
y = a.pop(a.index(max(a)))
for i in a:
  if i >= 0:
    if x >= y:
      y += i
    else:
      x += i
  else:
    if x >= y:
      x += i
    else:
      y += i
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True,key=lambda x:abs(x))
x = a.pop(0)
y = a.pop(0)
for i in a:
  if i >= 0:
    if x >= y:
      y += i
    else:
      x += i
  else:
    if x >= y:
      x += i
    else:
      y += i
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [abs(int(i)) for i in input().split()]
a.sort(reverse=True,key=lambda x:abs(x))
x = a.pop(0)
y = a.pop(0)
for i in a:
  if i >= 0:
    if x >= y:
      y += i
    else:
      x += i
  else:
    if x >= y:
      x += i
    else:
      y += i
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
x = a.pop(0)
y = a.pop(0)
for i in a:
  if i >= 0:
    if x >= y:
      y += i
    else:
      x += i
  else:
    if x >= y:
      x += i
    else:
      y += i
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = list(map(int,input().split()))
tmp = a[0]
ans = 2**30+1
S = sum(a)
for i in range(1,N-1):
    ans = min(ans,np.abs(S-2*tmp))
    tmp += a[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a = list(map(int,input().split()))
tmp = a[0]
ans = 2**30+1
S = sum(a)
for i in range(1,N):
    ans = min(ans,np.abs(S-2*tmp))
    tmp += a[i]
    
print(ans)

Submission status: Wrong Answer

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

s1 = 0
s2 = sum(a)
MIN = abs(a[0]-s2) 
for i in range(1,N):
    MIN = min(MIN,abs(s1-s2))
    s1 = s1+ a[i]
    s2 = s2 - a[i]
    
if N!= 2:
    print(s2)
else:
    print(abs(a[0] - a[1]))

Submission status: Wrong Answer

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

left = [0] * N
right = [0] * N

left[0] = a[0]
right[-1] = a[-1]
for i in range(1, N):
    left[i] = a[i] + left[i-1]
for i in range(N-2, -1, -1):
    right[i] = a[i] + right[i+1]

# print(left)
# print(right)
ans = abs(left[0] + right[1])
for i in range(1, N-1):
    ans = min(ans, abs(left[i] - right[i+1]))
print(ans)

Submission status: Wrong Answer

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

left_sum = [0] * (N - 1)
right_sum = [0] * (N - 1)

left_sum[0] = a[0]
right_sum[0] = a[-1]
for i in range(1,len(a) - 1):
    left_sum[i] = left_sum[i-1] + a[i]

for i in reversed(range(1,len(a) - 1)):
    right_sum[i] = right_sum[i-1] + a[i]


ans = 9999999999999999
for i in range(len(left_sum)):
    ans = min(ans, abs(left_sum[i] - right_sum[N-2-i]))
print(ans)

Submission status: Wrong Answer

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

left_sum = [0] * (N - 1)
right_sum = [0] * (N - 1)

left_sum[0] = a[0]
right_sum[0] = a[-1]
for i in range(1,len(a) - 1):
    left_sum[i] = left_sum[i-1] + a[i]

for i in reversed(range(1,len(a) - 1)):
    right_sum[i] = right_sum[i-1] + a[i]


ans = 999999
for i in range(len(left_sum)):
    ans = min(ans, abs(left_sum[i] - right_sum[N-2-i]))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = sum(a)
l = 0

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

print(ans)

Submission status: Wrong Answer

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

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

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 = abs(x-y)

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

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 = abs(x-y)

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

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 = abs(x-y)

for i in range(N-1):
    x += a[i+1]
    y -= a[i+1]
    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:])

ans = 10**9

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    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))


main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    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))


main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), 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))


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
sum_s= 0
sum_a = 0
diff = 100*100
for a in range(len(l)-1):
    sum_s = sum(l[:a+1])
    sum_a = sum(l[a+1:])
    if diff > abs(sum_s - sum_a):
        diff = abs(sum_s - sum_a)
print(diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
sum_s= 0
sum_a = 0
diff = 100000*100000
for a in range(len(l)):
    sum_s = sum(l[:a+1])
    sum_a = sum(l[a+1:])
    if diff > abs(sum_s - sum_a):
        diff = abs(sum_s - sum_a)
print(diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
sum_s= 0
sum_a = 0
diff = 100000*100000
for a in range(len(l)):
    sum_s = sum(l[:a+1])
    sum_a = sum(l[a+1:])
    if diff > abs(sum_s - sum_a):
        diff = abs(sum_s - sum_a)
    print(sum_s,sum_a)
print(diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
Sum = sum(l)
print(Sum)
a = Sum/2
b = 0
c = 0
if Sum > 0:
    for i in range(len(l)):
        b += l[i]
        if b > a:
            c = b - l[i]
            break
if Sum < 0:
    for i in range(len(l)):
        b += l[i]
        if b < a:
            c = b
            break
if c == 0:
    c = l[0]
print(abs(c-(Sum-c)))

Submission status: Wrong Answer

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

sum_card = sum(card)
min_value = 1000000000
sunuke = card[0]
for i in range(1,N-1,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
Sum = sum(l)
print(Sum)
a = Sum/2
b = 0
c = 0
if Sum > 0:
    for i in range(len(l)):
        b += l[i]
        if b > a:
            c = b - l[i]
            break
if Sum < 0:
    for i in range(len(l)):
        b += l[i]
        if b < a:
            c = b - l[i]
            break
if c == 0:
    c = l[0]
print(abs(c-(Sum-c)))

Submission status: Wrong Answer

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

sum_card = sum(card)
min_value = 1000000000
sunuke = card[0]
for i in range(1,N,1):
  sunuke += card[i]
  if abs(sum_card - 2*sunuke) < min_value:
    min_value = abs(sum_card - 2*sunuke)
  
print(int(min_value))

Submission status: Wrong Answer

Solution code:
N = int(input())
card = list(map(int,input().split(' ')))
 
sum_card = sum(card)
dif_list = []
min_value = 1000000000
sunuke = card[0]
for i in range(1,N,1):
  sunuke += card[i]
  if abs(sum_card/2 - sunuke) < min_value:
    min_value = abs(sum_card/2 - sunuke)
  
print(int(2*min_value))

Submission status: Wrong Answer

Solution code:
N = int(input())
card = list(map(int,input().split(' ')))
 
sum_card = sum(card)
dif_list = []
min_value = 1000000000
sunuke = 0
for i in range(0,N,1):
  sunuke += card[i]
  if abs(sum_card/2 - sunuke) < min_value:
    min_value = abs(sum_card/2 - sunuke)
  
print(int(2*min_value))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
Sum = sum(l)
a = Sum/2
b = 0
c = 0
for i in range(len(l)):
    b += l[i]
    if b > a:
        c = b - l[i]
        break
if c == 0:
    c = l[0]
print(abs(c-(Sum-c)))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
abs_l=list(map(abs,l))
max_index=(abs_l.index(max(abs_l)))
left=l.pop(max_index)
abs_l.pop(max_index)
max_index=(abs_l.index(max(abs_l)))
right=l.pop(max_index)
abs_l=list(map(abs,l))
abs_l.sort(reverse=True)
for _ in range(n-2):
  if left>right:
    right+=abs_l.pop(0)
  else:
    left+=abs_l.pop(0)
print(abs(left-right))

Submission status: Wrong Answer

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

snuke=0
araiguma=sum(a)
ans=10**15

for i in range(N-2):
    snuke+=a[i]
    araiguma-=a[i]
    ans=min(ans,abs(snuke-araiguma))

print(ans)

Submission status: Wrong Answer

Solution code:
input()
l = list(map(int,input().split()))
s = 0
m = 1000000000000
for i in range(len(l)-1):
    s += l[i]
    if(m > abs(s-sum(l[i+1:]))):
        m = abs(s-sum(l[i+1:]))
    else:
        break
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = 0
ABS = 0
min = -1
loop = 0
SUM = sum(a)

for i in range(N-1):
    for j in range(i + 1):
        x += a[j]
        if (min != -1 and abs(2*x - SUM) > min):
            break
    else:
        ABS = abs(2*x - SUM)
        x = 0
        if (min == -1 or min > ABS):
            min = ABS

print(min)

Submission status: Wrong Answer

Solution code:
input()
l = list(map(int,input().split()))
s = 0
b = 0
m = 1000000000000
for i in range(len(l)-1):
    s += l[i]
    b += l[len(l)-(i+1)]
    if(m > abs(s-sum(l[i+1:]))):
        m = abs(s-sum(l[i+1:]))
    if(m > abs(sum(l[:-(i+1)])-b)):
        m = abs(sum(l[:-(i+1)])-b)
    if(not (m >= abs(s-sum(l[i+1:]))) and not (m >= abs(sum(l[:-(i+1)])-b))):
        break
print(m)

Submission status: Wrong Answer

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

min_diff = 10**9
ave = sum(list_a) / 2
count = 0
for i in range(len(list_a)-1):
    sunuke = sum(list_a[:i+1])
    if sunuke > ave:
        count += 1
        if count == 2:
            break
    arai = sum(list_a[i+1:])

    if min_diff > abs(sunuke - arai):
        min_diff = abs(sunuke - arai)

print(min_diff)

Submission status: Wrong Answer

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

min_diff = 10**9
ave = sum(list_a) / len(list_a)
count = 0
for i in range(len(list_a)-1):
    sunuke = sum(list_a[:i+1])
    if sunuke > ave:
        count += 1
        if count == 2:
            break
    arai = sum(list_a[i+1:])
    diff = abs(sunuke - arai)
    if min_diff > diff:
        min_diff = diff

print(min_diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
AABBSS = 0
aabbss = 0
min = 0

for i in range(N-1):
    AABBSS = sum(a)
    for j in range(i + 1):
        AABBSS -= a[j]
        aabbss += a[j]
    else:
        if (min == 0 or min > abs(AABBSS - aabbss)):
            min = abs(AABBSS - aabbss)
        aabbss = 0
        AABBSS = 0
else:
    print(min)

Submission status: Wrong Answer

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

min_diff = 10**9
ave = sum(list_a) / len(list_a)
for i in range(len(list_a)-1):
    sunuke = sum(list_a[:i+1])
    if sunuke > ave:
        break
    arai = sum(list_a[i+1:])
    diff = abs(sunuke - arai)
    if min_diff > diff:
        min_diff = diff

print(min_diff)

Submission status: Wrong Answer

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

min_diff = 10**9
for i in range(len(list_a)-1):
    sunuke = sum(list_a[:i+1])
    arai = sum(list_a[i+1:])
    diff = abs(sunuke - arai)
    if min_diff > diff:
        min_diff = diff

print(min_diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
AABBSS = 0
aabbss = 0
min = 0

for i in range(N-1):
    for j in range(i + 1):
        AABBSS += a[j]
    else:
        for k in range(i+1,N):
            aabbss += a[k]
        else:
            if (min == 0 or min > abs(AABBSS - aabbss)):
                min = abs(AABBSS - aabbss)
            aabbss = 0
            AABBSS = 0
else:
    print(min)

Submission status: Wrong Answer

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

min_diff = 10**9
for i in range(len(list_a)-1):
    sunuke = sum(list_a[:i+1])
    arai = sum(list_a[i+1:])
    if min_diff > abs(sunuke - arai):
        min_diff = abs(sunuke - arai)

print(min_diff)

Submission status: Wrong Answer

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

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

ans = 10**9

for a in A[:-1]:
    if ans > abs(2*a - sm):
        ans = abs(2*a - sm)

print(ans)

Submission status: Wrong Answer

Solution code:
# num = int(input())
# h, w = list(map(int, input().split()))
# arr = list(map(int, input().split()))

num = int(input())
org_list = list(map(int, input().split()))

new_list_reverse = sorted(org_list, reverse=True)

count = 0
num_cut = -(-num // 2)
for i in range(num_cut):
    if i==0:
        pre_min_diff = abs(sum(new_list_reverse[:i+1])-sum(new_list_reverse[i-num+1:]))
        min_diff = abs(sum(new_list_reverse[:i+1])-sum(new_list_reverse[i-num+1:]))
    else:
        min_diff = abs(sum(new_list_reverse[:i+1])-sum(new_list_reverse[i-num+1:]))

    if min_diff < pre_min_diff:
        pre_min_diff = min_diff

print(pre_min_diff)

Submission status: Wrong Answer

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

ls = []
ls.append(a[0])

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

Sum = ls[-1]
ans = 10**9
for i in range(0,n-1):
    ans = min(abs(Sum-2*ls[i]),ans)

print(ans)

Submission status: Wrong Answer

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

ls = []
ls.append(a[0])

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

Sum = ls[-1]
ans = 10**9
for i in range(0,n-1):
    ans = min(abs(Sum-2*ls[i]),ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
list_a = map(int, input().split())
list_a = list(list_a)
total = sum(list_a)
l = 0
res = 100000000000
if n == 2:
    print(abs(list_a[0] - list_a[1]))
else:
    for i in range(0, n):
        #print("---")
        #print(l)
        #print(total)
        l += list_a[i]
        total -= list_a[i]
        res = min(res, abs(l - total))
    print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
    sum_n = sum(A)
    mid = sum_n / 2
    a = 0
    abs_list = []
    for i in range(N - 1):
        a += A[i]
        abs_list.append((abs(mid - a), sum_n - a))    
    abs_list.sort()
    print(abs_list[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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


print(min([abs(i-j) for i, j in zip(left[1:], right[:-1][::-1]) if i != 0 and j != 0]))

Submission status: Wrong Answer

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

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

print(min([abs(i-j) for i, j in zip(left, right[::-1])]))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

ans = 10**9
l = [a[0]]
r = [a[-1]]
# print(l,r)
for i in range(1,n-1):
	l = l+[l[i-1]+a[i]]
	r = [r[-i]+a[-i-1]]+r
# print(l,r)
for i in range(n-1):
	res = abs(l[i]-r[i])
	ans = min(res,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):
	res = abs(sum(a[:i])-sum(a[i:]))
	if ans > res:
		ans = res
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
A = [int(v) for v in input().split()]
A.sort()
p = sum(A)
L = [0] * (N + 1)

for i in range(N):
    L[i + 1] = L[i] + A[i]

ans = 10 ** 18
for i in range(N - 1):
    t = L[i + 1] - L[0]

    ans = min(ans, abs(t - p + t))

print(ans)