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

a = sorted(a)
X = sum(a)

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

print(min(ans))

Submission status: Wrong Answer

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

a = sorted(a)

ans = []
for i in range(1, N):
    ans.append(abs(sum(a[:i]) - sum(a[i:])))

print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
tmpval = sum(A)
minval = abs(tmpval)
for a in A:
    tmpval -= 2*a
    minval = min(minval, abs(tmpval))
print(minval)

Submission status: Wrong Answer

Solution code:
N = int(input())
cards = list(map(int, input().split()))
total = sum(cards)

subtotals = [cards[0]]
for i in range(1, N - 1):
    subtotals.append(subtotals[i - 1] + cards[i])

ans = 10**9
for subtotal in subtotals:
    ans = min(ans, abs(total - 2*subtotal))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = float('inf')
for i in range(N):
	x = sum(a[:i])
	y = sum(a[i:])
	if abs(x-y) < ans:
		ans = abs(x-y)
if N == 2:
	ans = abs(a[0]-a[1])
print(ans)

Submission status: Wrong Answer

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

n = int(input())
A = list(map(int, input().split()))
half = sum(A)//2
d = A[0]
y = -1
s = sum(A)
A.pop()

for i in range(1, n-1):
    a = A[i]
    if d + a > half:
        y = d + a
        break
    else:
        d += a

if y == -1:
    print(abs(2*d - s))
else:
    print(min(abs(s - 2*d), abs(2*y - s)))

Submission status: Wrong Answer

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

n = int(input())
A = list(map(int, input().split()))
half = sum(A)//2
d = A[0]
y = -1
s = sum(A)
A.pop()

for i in range(1, n-1):
    a = A[i]
    if d + a > half:
        y = d + a
        break
    else:
        d += a

if y == -1:
    print(2*d - s)
else:
    print(min(s - 2*d, 2*y - s))

Submission status: Wrong Answer

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

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

s = sum(nums)
x = 0
y = 0
for i in range(N):
    a = nums[i]
    if x + a <= s//2:
        x += a
    else:
        y = x + a
        break
    
if x == 0:
    x = nums[0]
if y == s:
    print(s-2*x)
else:
    print(min(s-2*x, 2*y-2))

Submission status: Wrong Answer

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

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

s = sum(nums)
x = 0
y = 0
for i in range(N):
    a = nums[i]
    if x + a <= s//2:
        x += a
    else:
        y = x + a
        break
    
if x == 0:
    x = nums[0]
if y == s:
    y = 0

print(min(s-2*x, 2*y-2))

Submission status: Wrong Answer

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

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

s = sum(nums)
x = 0
y = 0
for i in range(N):
    a = nums[i]
    if x + a <= s//2:
        x += a
    else:
        y = x + a
        break
    print(x)
if x == 0:
    x = nums[0]
if y == s:
    y = 0

print(min(s-2*x, 2*y-2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)

mydata=0
for i in range(0,n):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = sorted(list(map(int,input().split())))
ssunke = 0
sarai = 0
if N%2 != 0:
    ssunke += arr[N-1]
    arr.pop(-1)
for i in range(len(arr)//2):
    if ssunke <= sarai:
        ssunke += arr[2*i+1]
        sarai += arr[2*i]
    else:
        ssunke += arr[2*i]
        sarai += arr[2*i+1]
print(abs(ssunke-sarai))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted(list(map(int,input().split())))
csum = [0 for _ in range(N+1)]
csum[0] = 0
for i in range(1,N+1):
    csum[i] = csum[i-1] + a[i-1]
left = 0
right = 1
avr = csum[N]//2
mins = 10**10
while(left < right and right < N):
    cards = csum[right]-csum[left]
    if cards == avr:
        mins = avr
        break
    else:
        if abs(cards - avr) < abs(mins - avr):
            mins = cards
        if cards > avr:
            left += 1
        else:
            right += 1
print(abs(csum[N]-2*mins))

Submission status: Wrong Answer

Solution code:
#067-C
n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n):
    mm=min(mm,abs(sa[i]-(sa[n-1]-sa[i])))
print(int(mm))

Submission status: Wrong Answer

Solution code:
#067-C
n=int(input())
a=list(map(int,input().split()))
sa=[a[0] for i in range(n)]
for i in range(1,n):
    sa[i]=sa[i-1]+a[i]
mm=float("INF")
for i in range(n):
    mm=min(mm,abs(a[i]-(sa[n-1]-a[i])))
print(int(mm))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
A=np.array(list(map(int,input().split())))
if n==2:
  print(abs(A[0]-A[1]))
else:
  cum=np.cumsum(A)
  ans= 10**100
  for i in range(n):
    a=cum[i]
    b=cum[-1]-a
    ans=min(ans,abs(a-b))
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
A=np.array(list(map(int,input().split())))
if n==2:
  print(abs(A[0]-A[1]))
else:
  cum=np.cumsum(A)
  ans= 10**9+7
  for i in range(n):
    a=cum[i]
    b=cum[-1]-a
    ans=min(ans,abs(a-b))
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
A=np.array(list(map(int,input().split())))
if n==2:
  print(abs(A[0]-A[1]))
else:
  cum=np.cumsum(A)
  ans= 10**9+7
  for i in range(n):
    a=cum[i]
    b=cum[-1]-a
    ans=min(ans,abs(b-a))
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==2:
  print(abs(A[0]-A[1]))
else:
  cum=np.cumsum(A)
  ans= 10**9
  for i in range(n):
    a=cum[i]
    b=cum[-1]-a
    ans=min(ans,abs(b-a))
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def getvalue(list,num):
  id=np.abs(np.asarray(list)-num).argmin()
  return id

n=int(input())
A=np.array(list(map(int,input().split())))
if n==2:
  print(abs(A[0]-A[1]))
else:
  ave=getvalue(A,round(np.average(A),0))
  cum=np.cumsum(A)
  ans= 10**9
  for i in range(n):
    a=cum[i]
    b=cum[-1]-a
    ans=min(ans,abs(b-a))
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def getvalue(list,num):
  id=np.abs(np.asarray(list)-num).argmin()
  return id

n=int(input())
A=np.array(list(map(int,input().split())))
if n==2:
  print(abs(A[0]-A[1]))
else:
  ave=getvalue(A,round(np.average(A),0))
  cum=np.cumsum(A)
  a=cum[3]
  b=cum[-1]-a
  print(abs(b-a))

Submission status: Wrong Answer

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

b = []
while True:
    if a[0] < 0:
        b.append(a.pop(0))
    if a[0] >= 0:
        break

if a == []:
    a = list(map(lambda x: -x, b))[-1::-1]

x = a.pop()
y = 0
if n == 2 and len(b) == 1:
    y = b.pop()
    print(abs(x-y))
    exit()

while a:
    if x >= y:
        y += a.pop()
    else:
        x += a.pop()

while b:
    if x >= y:
        x += b.pop(0)
    else:
        i = 1
        y += b.pop(0)

print(abs(x-y))

Submission status: Wrong Answer

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

ans=1000000000000000
B=[A[0]]
for i in range(1,N):
    B.append(B[i-1]+A[i])

S=sum(A)

for j in range(N-1):
    if abs(S-B[j])<ans:
        ans=abs((S-B[j])-B[j])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*(N-1)
number_sum[0]=number[0]

for i in range(1,N-1):
  number_sum[i]=abs((number[i-1]+number[i])*2-SUM)

print(min(number_sum))

Submission status: Wrong Answer

Solution code:
N=int(input())
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*(N-1)

for i in range(N-1):
  number_sum[i]=sum(number[:i+1])*2-SUM

print(abs(max(number_sum)))

Submission status: Wrong Answer

Solution code:
N=int(input())
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*N

for i in range(N):
  number_sum[i]=sum(number[:i+1])*2-SUM

print(abs(max(number_sum)))

Submission status: Wrong Answer

Solution code:
N=int(input())
number=list(map(int,input().split()))
SUM=sum(number)
number_sum=[0]*N

for i in range(N):
  number_sum[i]=sum(number[0:i])*2-SUM

print(abs(max(number_sum)))

Submission status: Wrong Answer

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

sunuke = a[0]
araiguma = sum(a[1:])
diff = abs(sunuke - araiguma)

for i in a:
    sunuke += i
    araiguma -= i
    diff = min(diff, abs(sunuke - araiguma))

print(diff)

Submission status: Wrong Answer

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

i = N // 2
sunuke = sum(a[:i])
araiguma = sum(a[i:])

diff = abs(sunuke - araiguma)

if N == 2:
    pass
else:
    if sunuke > araiguma:
        while sunuke > araiguma:
            sunuke -= a[i]
            araiguma += a[i]
            i -= 1
            diff = min(diff, abs(sunuke - araiguma))
    elif sunuke < araiguma:
        while sunuke < araiguma:
            sunuke += a[i]
            araiguma -= a[i]
            i += 1
            diff = min(diff, abs(sunuke - araiguma))

print(diff)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()], key=lambda x: abs(x),reverse=True)
ans = 0
pos = False
neg = False
for i in range(N):
    a = A[i]
    if ans * a > 0:
        ans -= a
        neg = True
    else:
        ans += a
        pos = True
if pos & neg:
    print(abs(ans))
else:
    print(abs(A[-1]-sum(A[:-1])))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()])
ans = 0
while A:
    a = A.pop()
    if ans > 0:
        ans -= a
    else:
        ans += a
print(abs(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
imos = [a[i] for i in range(n)]
for i in range(1, n):
    imos[i] += a[i - 1]
diff = abs(imos[-1] - 2 * a[0])
for i in range(1, n-1):
    diff = min(diff, abs(imos[-1] - 2 * a[i]))
print(diff)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = 10**9
a_total = sum(a_list)
x = 0

for i in range(0,len(a_list)):
    x += abs(a_list[i])
    ans = min(abs(a_total-2*x),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = 10**9
a_total = sum(a_list)
x = a_list[0]

for i in range(1,len(a_list)):
    x += a_list[i]
    ans = min(abs(a_total-2*x),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = 10**9
a_total = sum(a_list)

for i in range(1,len(a_list)):
    x = sum(a_list[:i])
    ans = min(abs(a_total-2*x),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ans = 10**9

for i in range(1,len(a_list)):
    diff = abs(sum(a_list[:i])-sum(a_list[i:]))
    ans = min(ans,diff)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
a_list.sort(reverse=True)
x = 0
y = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_A = sum(A)
ans = 10**15
for i in range(N-1):
    dif = abs(sum_A - 2*A[i])
    sum_A = dif
    if dif < ans:
        ans = dif
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = sum(A)
ans = 10**15
def dif_min(x,y):
    return min(abs(2*x-sum_A),abs(2*y-sum_A))
for i in range(N-1):
    count += A[i] 
    if (sum_A > 0 and count >= sum_A / 2)\
    or (sum_A < 0 and count <= sum_A / 2)\
    or (sum_A == 0 and count * A[0] < 0):
        x = count 
        y = count - A[i]
        if dif_min(x,y) < ans:
            ans = dif_min(x,y)
    elif i == N-2:
        x = count
        y = A[0]
        ans = dif_min(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = sum(A)
ans = 10**15
def dif_min(x,y):
    return min(abs(2*x-sum_A),abs(2*y-sum_A))
for i in range(N-1):
    count += A[i] 
    if (sum_A > 0 and count >= sum_A / 2)\
    or (sum_A < 0 and count <= sum_A / 2)\
    or (sum_A == 0 and count * A[0] < 0):
        x = count 
        y = count - A[i]
        if dif_min(x,y) < ans:
            ans = dif_min(x,y)
    elif i == N-2:
            ans = abs(2*count-sum_A)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = sum(A)
ans = 10**9
def dif_min(x,y):
    return min(abs(2*x-sum_A),abs(2*y-sum_A))
for i in range(N-1):
    count += A[i] 
    if (sum_A > 0 and count >= sum_A / 2)\
    or (sum_A < 0 and count <= sum_A / 2)\
    or (sum_A == 0 and count * A[0] < 0):
        x = count 
        y = count - A[i]
        if dif_min(x,y) < ans:
            ans = dif_min(x,y)
    elif i == N-2:
            ans = abs(2*count-sum_A)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = sum(A)
for i in range(N-1):
    count += A[i] 
    if sum_A > 0 and count >= sum_A / 2:
        x1 = count 
        x2 = count - A[i]
        break
    elif sum_A < 0 and count <= sum_A / 2:
        x1 = count 
        x2 = count - A[i]
        break
    elif sum_A == 0 and count * A[0] < 0:
            x1 = count 
            x2 = count - A[i]
            break
    elif i == N-2:
            x1 = count 
            x2 = count
dif1 = abs(2*x1 - sum_A)
dif2 = abs(2*x2 - sum_A)
print(min(dif1,dif2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
sum_A = sum(A)
for i in range(N-1):
    count += A[i] 
    if sum_A > 0 and count >= sum_A / 2:
        x1 = count 
        x2 = count - A[i]
        break
    elif sum_A < 0 and count <= sum_A / 2:
        x1 = count 
        x2 = count - A[i]
    elif sum_A == 0 and count * A[0] < 0:
            x1 = count 
            x2 = count - A[i]
    elif i == N-2:
            x1 = count 
            x2 = count
dif1 = abs(2*x1 - sum_A)
dif2 = abs(2*x2 - sum_A)
print(min(dif1,dif2))

Submission status: Wrong Answer

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

r = []

ruiseki = 0
for val in a:
    ruiseki += val
    r.append(ruiseki)

ans = 999999999
for i in range(N-1):
    if ans > abs(r[-1] - r[i] - r[i]):
        ans = abs(r[-1] - r[i] - r[i])

print(ans)

Submission status: Wrong Answer

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

for i in range(N-1) :
    if i == 0 :
        p = L[i]
        q = sum(L)-p
        ans = abs(p-q)
    else :
        p += L[i]
        q -= L[i]
        if ans < abs(p-q) :
            ans = abs(p-q)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
iN = int(input())
aA = [int(_) for _ in input().split()]

iD = sum(aA)
iF = 0
iB = iD
minDiff = 10**9
for a in aA[:-1] :
    iF += a
    iB -= a
    thisDiff = abs(iF - iB)
    minDiff = min(minDiff , thisDiff)
print(minDiff)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x, y = A[0], A[-1] 
for i in range(1, N-1):
    if x <= y:
        x += A[i]
    else:
        y += A[i]
print(abs(x - y))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)

sunuke_l = []
sunuke = 0
arai_l = []
arai = 0
for ai in a:
    if ai > 0:
        if sunuke < arai:
            sunuke_l.append(ai)
            sunuke += ai
        elif sunuke > arai:
            arai_l.append(ai)
            arai += ai
        else:
            if len(sunuke_l) < len(arai_l):
                sunuke_l.append(ai)
                sunuke += ai
            else:
                arai_l.append(ai)
                arai += ai

    elif ai < 0:
        if sunuke > arai:
            sunuke_l.append(ai)
            sunuke += ai
        elif sunuke < arai:
            arai_l.append(ai)
            arai += ai
        else:
            if len(sunuke_l) < len(arai_l):
                sunuke_l.append(ai)
                sunuke += ai
            else:
                arai_l.append(ai)
                arai += ai
    else:
        if len(sunuke_l) < len(arai_l):
            sunuke_l.append(ai)
            sunuke += ai

        else:
            arai_l.append(ai)
            arai += ai

# print(a)
# print(sunuke,sunuke_l)
# print(arai,arai_l)

if len(sunuke_l) * len(arai_l) == 0:
    print(abs(sunuke - arai)+abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)

sunuke_l = []
sunuke = 0
sunuke_cnt = 0
arai_l = []
arai = 0
arai_cnt = 0
for ai in a:
    if ai > 0:
        if sunuke < arai:
            sunuke += ai
            sunuke_cnt += 1
            sunuke_l.append(ai)
        elif sunuke > arai:
            arai += ai
            arai_cnt += 1
            arai_l.append(ai)
        else:
            if len(sunuke_l) < len(arai_l):
                sunuke_l.append(ai)
                sunuke += ai
                sunuke_cnt += 1
            else:
                arai_l.append(ai)
                arai += ai
                arai_cnt += 1

    elif ai < 0:
        if sunuke > arai:
            sunuke += ai
            sunuke_cnt += 1
            sunuke_l.append(ai)
        elif sunuke < arai:
            arai += ai
            arai_cnt += 1
            arai_l.append(ai)
        else:
            if len(sunuke_l) < len(arai_l):
                sunuke_l.append(ai)
                sunuke += ai
                sunuke_cnt += 1
            else:
                arai_l.append(ai)
                arai += ai
                arai_cnt += 1
    else:
        if len(sunuke_l) < len(arai_l):
            sunuke_l.append(ai)
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai_l.append(ai)
            arai += ai
            arai_cnt += 1

# print(a)
# print(sunuke_l)
# print(arai_l)


if sunuke_cnt * arai_cnt == 0:
    print(abs(sunuke - arai)+abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)
# print(a)

sunuke = 0
sunuke_cnt = 0
arai = 0
arai_cnt = 0
for ai in a:
    if ai > 0:
        if sunuke <= arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    elif ai < 0:
        if sunuke > arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    else:
        sunuke_cnt += 1
        arai_cnt += 1

if sunuke_cnt * arai_cnt == 0:
    print(abs(sunuke - arai)+abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)
# print(a)

sunuke = 0
sunuke_cnt = 0
arai = 0
arai_cnt = 0
for ai in a:
    if ai > 0:
        if sunuke <= arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    elif ai < 0:
        if sunuke > arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    else:
        sunuke += ai
        arai_cnt += 1

if sunuke_cnt * arai_cnt == 0:
    print(abs(sunuke - arai)+abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)
# print(a)

sunuke = 0
sunuke_cnt = 0
arai = 0
arai_cnt = 0
for ai in a:
    if ai >= 0:
        if sunuke <= arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    else:
        if sunuke > arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1

if sunuke_cnt * arai_cnt == 0:
    print(abs(sunuke - arai)+abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)
# print(a)

sunuke = 0
sunuke_cnt = 0
arai = 0
arai_cnt = 0
for ai in a:
    if ai >= 0:
        if sunuke <= arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1
    else:
        if sunuke > arai:
            sunuke += ai
            sunuke_cnt += 1
        else:
            arai += ai
            arai_cnt += 1

if sunuke_cnt * arai_cnt == 0:
    print(abs(a[-1]*2))
else:
    print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

a.sort(key=lambda x: -abs(x))
# a.sort(reverse=True)
# print(a)

sunuke = 0
arai = 0
if len(a) == 2:
    sunuke += a[0]
    arai += a[1]
else:
    for ai in a:
        if ai >= 0:
            if sunuke <= arai:
                sunuke += ai
            else:
                arai += ai
        else:
            if sunuke > arai:
                sunuke += ai
            else:
                arai += ai

print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

sunuke = 0
arai = 0
for ai in a:
    if ai >= 0:
        if sunuke <= arai:
            sunuke += ai
        else:
            arai += ai
    else:
        if sunuke > arai:
            sunuke += ai
        else:
            arai += ai

print(abs(sunuke - arai))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

sunuke = 0
arai = 0
for ai in a:
    if sunuke <= arai:
        sunuke += ai
    else:
        arai += ai

print(abs(sunuke - arai))

Submission status: Wrong Answer

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

x = 0
y = 0
for i in range(n):
    y += a[i]
min = 1e9
for i in range(n-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < min:
        min = abs(x-y)
print(min)

Submission status: Wrong Answer

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

x = 0
y = 0
for i in range(n):
    y += a[i]
min = 2*y
for i in range(n-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < min:
        min = abs(x-y)
print(min)

Submission status: Wrong Answer

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

x = 0
y = 0
for i in range(n):
    y += a[i]
min = y
for i in range(n-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < min:
        min = abs(x-y)
print(min)

Submission status: Wrong Answer

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

x = 0
y = 0
min = 1e9
for i in range(n):
    y += a[i]
for i in range(n-1):
    x += a[i]
    y -= a[i]
    if abs(x-y) < min:
        min = abs(x-y)
print(min)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    X = sum(l)
    for i in range(N-1):
        ans.append(abs(X-2*l[i]))
        X -= l[i]
    print(min(ans))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    l = list(map(int, input().split()))
    ans = []
    sunuke = 0
    arai = sum(l)
    for i in range(N-1):
        sunuke += l[i]
        arai   -= l[i]
        ans.append(abs(sunuke-arai))
    print(min(l))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = int(1e9)
for i in range(1, N):
    x = sum(a[:i])
    y = sum(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()))
sunu=A[0]
m=abs(sum(A)-2*sunu)
for i in range(N):
    sunu+=A[i]
    if m>=abs(sum(A)-2*sunu):
        m=abs(sum(A)-2*sunu)
    else:
        print(m)
        exit()
print(m)

Submission status: Wrong Answer

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