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.sort()
now = 0
for i in range(N):
  now += abs(a[i])
p = now//2
snuke = 0
arai = 0
for i in range(N):
  snuke += a[i]
  if snuke >= p:
    arai = sum(a)-snuke
    break
print(abs(snuke-arai))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 1000000007
for i in range(1, len(a)):
  x = sum(a[0:i])
  y = sum(a[i:len(a)])
  if abs(x - y) < ans:
    ans = abs(x - y)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

s = 0
for a in A:
  d[a] += 1
  s += a
t = s//2

c = 0
for k, v in d.items():
  c += k*v
  if c >= t:
    c -= k*v
    for i in range(v):
      c += k
      if c >= t:
        print(s-2*c)
        break
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
M = sum(a)
snk = 0
ans = float('inf')
for i in range(N-1):
    snk += a[i]
    ari = M - snk
    ans = min(ans,abs(snk-ari))
print(ans)

Submission status: Wrong Answer

Solution code:
INF = 300000
N = int(input())
points = list(map(int, input().split()))
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])
ans = INF
last = sums[-1]
for s in sums[1:-1]:
  ans = min(ans, abs(last -s - s))
print(ans)

Submission status: Wrong Answer

Solution code:
INF = 300000
import sys
N = int(input())

# 累積和使ったらO（N）で終わる
points = list(map(int, input().split()))

if len(points) == 2:
  print(abs(points[1] - points[0]))
  sys.exit()

# 累積和の配列実装
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])

ans = INF
last = sums[-1]
for s in sums[1:-1]:
  ans = min(ans, abs(last -s - s))
print(ans)

Submission status: Wrong Answer

Solution code:
INF = 300000
import sys
N = int(input())

# 累積和使ったらO（N）で終わる
points = list(map(int, input().split()))

if len(points) == 2:
  print(abs(points[1] - points[0]))
  sys.exit()

# 累積和の配列実装
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])

mi = INF
ma = sums[-1]
for s in sums[1:-1]:
  mi = min(mi, abs(ma-s - s))
print(mi)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

# 累積和使ったらO（N）で終わる
points = list(map(int, input().split()))

if len(points) == 2:
  print(abs(points[1] - points[0]))
  sys.exit()

# 累積和の配列実装
sums = [0]
for index in range(len(points)):
  sums.append(points[index]+sums[index])

mi = sums[-1]
ma = sums[-1]
for s in sums:
  mi = min(mi, abs(ma-s - s))
print(mi)

Submission status: Wrong Answer

Solution code:
n = int(input())

list = list(map(int, input().split()))
all = sum(list)
ans = 10**10
sunuke = 0

for i in range(0,n-1):
    sunuke = list[i]
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

list = list(map(int, input().split()))
all = sum(list)
ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:i+1])
    arai = all - sunuke
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:i+1])
    arai = sum(list[i+1:n])
    sa = abs(sunuke - arai)
   
    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:1])
    arai = sum(list[i+1:n])
    sa = abs(sunuke - arai)

    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:1])
    arai = sum(list[i+1:n])
    sa = abs(sunuke - arai)
    print(sunuke)
    print(arai)
    
    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 999999999

for i in range(0,n-1):
    sunuke = sum(list[0:i])
    arai = sum(list[i+1:n-1])
    sa = abs(sunuke - arai)
    if sa < ans:
      ans = sa

print(ans)

Submission status: Wrong Answer

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

su = sum(a)
mini = 10**10
x = 0

for i in range(n):
    x += a[i]
    y = su - x
    diff = abs(x - y)

    if diff < mini:
        mini = diff

print(mini)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#-----

cumulative_sum=["_"]*len(a_list)
cumulative_sum[0] = a_list[0]
for i in range(1,len(a_list)):
    cumulative_sum[i] = cumulative_sum[i-1] + a_list[i]

min_diff = abs(cumulative_sum[N-1])
for v in cumulative_sum[:-1]:
    diff = abs( 2*v - cumulative_sum[N-1] )
    min_diff = min(min_diff, diff)

print(min_diff)

Submission status: Wrong Answer

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

first_half = l[0]
second_half = sum(l[1:])
diff = abs(first_half - second_half)

for i in l[1:len(l)-1]:
    first_half += i
    second_half -= i
    if abs(first_half - second_half) < diff:
        diff = abs(first_half - second_half)
    else:
        break

print(diff)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
cards=[int(b) for b in a]
whole=sum(cards)
half=whole//2
for c in range(len(cards)-1):
    sunuke=cards[:c+1]
    arai=cards[c+1:]
    if sum(sunuke)>=half:
        print((abs(sum(sunuke) - sum(arai))))
        break

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
cards=[int(b) for b in a]
answers=[]
whole=sum(cards)
half=whole//2
for c in range(len(cards)-1):
    sunuke=cards[:c+1]
    arai=cards[c+1:]
    answers.append(abs(sum(sunuke)-sum(arai)))
    if sum(sunuke)>=half:
        break
print(min(answers))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def test(L):
    T = abs(sum(A[:L]) - sum(A[L:]))
    return T <= answer


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

left = 0
right = N
answer = abs(A[0] - sum(A[1:]))
while left + 1 < right:
    L = (left + right) // 2
    if test(L):
        answer = abs(sum(A[:L]) - sum(A[L:]))
        left = L
    else:
        right = L


print(answer)

Submission status: Wrong Answer

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

ans = float('inf')
X = sum(a_l)
for a in a_l:
    ans = min(ans, abs(X - 2*a))

print(ans)

Submission status: Wrong Answer

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


a_l.sort(reverse=True)
x = a_l[0]
y = a_l[1]
for a in a_l[2:]:
    if x <= y:
        if a < 0:
            y += a
        else:
            x += a
    else:
        if a < 0:
            x += a
        else:
            y += a

print(abs(x-y))

Submission status: Wrong Answer

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


a_l.sort(reverse=True)
x = 0
y = 0
for a in a_l:
    if x <= y:
        if a < 0:
            y += a
        else:
            x += a
    else:
        if a < 0:
            x += a
        else:
            y += a

print(abs(x-y))

Submission status: Wrong Answer

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

#%%
a_l.sort(reverse=True)
x = 0
y = 0
for a in a_l:
    if x <= y:
        x += a
    else:
        y += a

print(abs(x-y))

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  a = list(input_list())
  sa = sum(a)
  ans = 10**9
  r = 0
  for v in list(a)[:-1]:
    r += v
    ans = min(ans, abs(sa - (2*r)))
  print(ans)

def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Submission status: Wrong Answer

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

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

ans = 1e9
for i in range(1, N):
  p1 = cusum[i]
  p2 = cusum[-1] - cusum[i]
  diff = abs(p1 - p2)
  ans = min(diff, ans)

print(ans)

Submission status: Wrong Answer

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

a_sum = []
x = 0

for i in range(N):
    x += a[i]
    a_sum.append(x)
    
ans = 10**9+1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

total = sum(data)
x = 0
ans = 2 * 10**9 + 1
last = data[-1]
for i in data:
    if i == last: break
    x += i
    score = abs(2*x - total)
    if score < ans:
        ans = score
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x, y = a[0], sum(a) - a[0]
r = abs(x-y)
idx = 1
while idx < n - 1:
    x += a[idx]
    y -= a[idx]
    d = abs(x-y)
    if r < d:
        break
    else:
        r = d
print(r)

Submission status: Wrong Answer

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

if len(a) == 2:
    y = a[-1]
    print(abs(x-y))
    exit()


total = sum(a)
mid = total//2

for i in range(1, N):
    x += a[i]
    if x <= mid:
        continue
    else:
        print(min(abs(x-a[i]-(total - (x-a[i]))), abs(x-(total - x))))
        exit()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    a = list(map(int, input().split()))
    res = 10**20
    total = sum(a)
    for i in range(n-1):
        total = abs(total - 2*a[i])
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    a = list(map(int, input().split()))
    res = 10**20
    total = abs(sum(a))
    for i in range(n-1):
        total = abs(total - 2*a[i])
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n = int(input())
    a = list(map(int, input().split()))
    res = 10**20
    total = abs(sum(a))
    for i in range(n-1):
        total = abs(total - 2*i)
        res = min(res, total)
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


s = sum(a)
m = pow(10, 9)
b = 0
for i in range(N-1):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    #print(a[i])
print(m)

Submission status: Wrong Answer

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


s = sum(a)
m = pow(10, 9)
b = a[0]
for i in range(1, N-1):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    #print(a[i])
print(m)

Submission status: Wrong Answer

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


s = sum(a)
m = pow(10, 9)
b = a[0]
for i in range(1, N-1):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    print(a[i])
print(m)

Submission status: Wrong Answer

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


s = sum(a)
m = pow(10, 9)
b = a[0]
for i in range(1, N):
    b += a[i]
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)

print(m)

Submission status: Wrong Answer

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


s = sum(a)
m = s - a[0]
#print(m)
for i in range(2, N):
    b = sum(a[:i])
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    else:
        break
print(m)

Submission status: Wrong Answer

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

m = pow(10, 9)

s = sum(a)
for i in range(1, N):
    b = sum(a[:i])
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
print(m)

Submission status: Wrong Answer

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

m = pow(10, 9)

s = sum(a)
for i in range(1, N):
    b = sum(a[:i])
    c = s - b
    #print(b)
    #print(c)
    if m > (abs(b-c)):
        m = abs(b-c)
    else:
        break
print(m)

Submission status: Wrong Answer

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

S=[0]*n
S[0]=A[0]
for i in range(1,n):
    S[i] += S[i-1] + A[i]

mean=S[n-1]//2

def binary_search(data,value):
    left=0
    right=len(data)-1
    mid = (left+right)//2
    while right-left > 3:
        mid = (left+right)//2
        if data[mid] == value:
            return data[mid]
        if data[mid] < value:
            left = mid + 1
        elif data[mid] > value:
            right = mid - 1
    d = float("inf")
    for s in (S[mid-1], S[mid], S[mid+1]):
        d = min(d, abs(mean- s))
    return d

if n >= 3:
    print(S[n-1] - 2*(mean - binary_search(S,mean)))
else:
    print(A[1]-A[0])

Submission status: Wrong Answer

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

S=[0]*n
S[0]=A[0]
for i in range(1,n):
    S[i] += S[i-1] + A[i]

mean=S[n-1]//2

def binary_search(data,value):
    left=0
    right=len(data)-1
    while right-left > 3:
        mid = (left+right)//2
        if data[mid] == value:
            return data[mid]
        if data[mid] < value:
            left = mid + 1
        elif data[mid] > value:
            right = mid - 1
    d = float("inf")
    for s in S[mid-1:mid+2]:
        d = min(d, abs(mean- s))
    return d

if n >= 3:
    print(S[n-1] - 2*(mean - binary_search(S,mean)))
else:
    print(A[1]-A[0])

Submission status: Wrong Answer

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

S=[0]*n
S[0]=A[0]
for i in range(1,n):
    S[i] += S[i-1] + A[i]

mean=S[n-1]/2

def binary_search(data,value):
    left=0
    right=len(data)-1
    while right-left > 3:
        mid = (left+right)//2
        if data[mid] == value:
            return data[mid]
        if data[mid] < value:
            left = mid + 1
        elif data[mid] > value:
            right = mid - 1
    d = float("inf")
    for s in S[mid-1:mid+2]:
        d = min(d, abs(mean- s))
    return d

if n >= 3:
    print(S[n-1] - 2*(mean - binary_search(S,mean)))
else:
    print(A[1]-A[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
x, y = 0, 0
ans = 10**9
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()))

sum_a = [0]
result = [abs(sum(a)-a[0]*2)]
for i in range(1, n-1):
    result.append(abs(result[-1]-2*a[i]))
print(min(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
x = 0
y = sum(a)
ans = 10e9
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()))
a.sort(reverse=True)

x,y=0,0
cnt_x,cnt_y=0,0
for i in range(n):
    if i==n-1:
        if cnt_x==0 :
            x+=a[i]
            break
        if cnt_y==0:
            y+=a[i]
            break        
    if a[i]>0:
        if x<=y:
            x+=a[i]
            cnt_x+=1
        else:
            y+=a[i]
            cnt_y+=1
    elif a[i]<0:
        if x<=y:
            y+=a[i]
            cnt_y+=1
        else:
            x+=a[i]
            cnt_x+=1
    else:
        if cnt_x==0:
            cnt_x+=1
        else:
            cnt_y+=1
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int,input().split())))
sum1 = 0
sum2 = sum(L)
ans = 10**10
for i in range(n):
    sum1 += L[i]
    sum2 -= L[i]
    ans = min(ans,abs(sum1 - sum2))

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n = int(input())
L = sorted(list(map(int,input().split())))
LL = list(accumulate(L))

sum1 = 0
sum2 = sum(L)
ans = 10**10
for i in range(n):
    sum1 += LL[i]
    sum2 -= LL[i]
    ans = min(ans,abs(sum1 - sum2))
print(ans)

Submission status: Wrong Answer

Solution code:
def pin(type=int):
    return map(type,input().split())

"""
"""

#solution:

#input
N,=pin()
A=list(pin())
S=sum(A)
s=A[0]
m=abs(S-s*2)
#print(m)
for i in range(1,N):
    s=s+A[i]
    t=abs(S-s*2)
    #print(t)
    m=min(t,m)
print(m)

Submission status: Wrong Answer

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

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

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

m = abs(cs[-1] - cs[0])
for i in range(1, n):
    temp = abs(abs(cs[-1] - cs[i]) - cs[i])
    m = min(m, temp)

print(m)

Submission status: Wrong Answer

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

x=[a[0]]

for i in range(1,n-1):
    x.append(x[i-1]+a[i])
y=[sum(a)-a[0]]
for i in range(1,n-1):
    y.append(y[i-1]-a[i])
#print(x)
#print(y)

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

Submission status: Wrong Answer

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

x=[a[0]]

for i in range(1,n-1):
    x.append(x[i-1]+a[i])
y=[sum(a)-a[0]]
for i in range(1,n-1):
    y.append(y[i-1]-a[i])
print(x)
print(y)

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

Submission status: Wrong Answer

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

a.sort(reverse=True )
x=a[0]
y=a[1]
for i in range(2,n):
    if a[i]<0:
        if x>y:
            x+=a[i]
        else:
            y+=a[i]
    else:
        if x<y:
            x+=a[i]
        else:
            y+=a[i]
print(max(x,y)-min(x,y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=a[0]
y=a[-1]
suma=sum(a)
for i in range(1,n-1):
    if x<suma//2:
        x+=a[i]
    else:
        break
y=suma-x
print(max(x,y)-min(x,y))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst1 = list(map(int,input().split()))
s = sum(lst1)
abs_ = 10**9+10
now = 0
i = 0
while True:
    now += lst1[i]
    if i >= n-1:
        break
    else:
        abs_ = min(abs_,abs(now-(s-now)))
    i += 1

print(abs_)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst1 = list(map(int,input().split()))
s = sum(lst1)
abs_ = 10**9
now = 0
i = 0
while True:
    now += lst1[i]
    if i >= n-1:
        break
    else:
        abs_ = min(abs_,abs(now-(s-now)))
    i += 1

print(abs_)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = 0
l = sum(A)
m = l
for a in A:
  s += a
  k = abs(l - 2*s)
  if m > k:
    m = k
print(m)

Submission status: Wrong Answer

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

x = sum(a)
y = 0
ans = 10000000000000000

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if N == 2:
  print(abs(A[0] - A[1]))
  sys.exit()

li = []

for index, a in enumerate(A):
  if index == 0:
    li.append(a)

  else:
    li.append(a + li[index-1])

ans = 10 ** 12


for index, i in enumerate(li):
  s = li[index]
  k = li[-1] - li[index]

  if ans > abs(s - k):
    ans = abs(s - k)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if N == 2:
  print(abs(A[0] - A[1]))
  sys.exit()

li = []

for index, a in enumerate(A):
  if index == 0:
    li.append(a)

  else:
    li.append(a + li[index-1])

ans = 10 ** 9


for index, i in enumerate(li):
  s = li[index]
  k = li[-1] - li[index]

  if ans > abs(s - k):
    ans = abs(s - k)

print(ans)

Submission status: Wrong Answer

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

A.sort(reverse=True)

s = 0
t = 0

for index, a in enumerate(A):
  if index % 4 == 0 or index % 4 == 3:
    s += a

  else:
    t += a

print(abs(s - t))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=float("inf")
S=[0]*(N+1)
S[0]=0
X=sum(A)
for i in range (1,N-1):
	S[i]=A[i-1]+S[i-1]

for i in range (N+1):
	ans=min(ans,(X-2*S[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
ans=float("inf")
for i in range (N-1):
	ans=min(ans,abs(B[i]-B[i+1]))
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
c_sum=sum(a)
val=0
if n==2:
	print(abs(a[0]-a[1]))
	sys.exit()
for i in range(n-1):
	val+=a[i]
	if val*2>c_sum:
		val1=abs((val)-(c_sum-val))
		val2=abs((val-a[i])-(c_sum-val+a[i]))
		break
print(min(val1,val2))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    g1 = a[0]
    g2 = sum(a[1:n])
    ans = abs(g1 - g2)
    if n > 2:
        for i in range(1, n):
            g1 += a[i]
            g2 -= a[i]
            tmp = abs(g1 - g2)
            if tmp < ans:
                ans = tmp

    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
sumA = 0
sumli = sum(a)
ans = 1000000000
for i in range(n):
    sumA += a[i]
    sumB = abs(sumli - sumA*2)
    ans = min(ans,sumB)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
sumA = 0
sumB = 0
ans = 1000000000
for i in range(1,n):
    sumA = sum(a[:i])
    sumB = sum(a[i:])
    ans = min(ans,abs(sumA-sumB))
print(ans)

Submission status: Wrong Answer

Solution code:
def splittingplie(n , a):

    ans = 10**18
    allsum = int(sum(a))
    asum = 0

    for i in range(n):
        asum += a[i]
        b = allsum - asum
        rldifference = abs(asum - b)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def splittingplie(n , a):

    ans = 100000000000000000
    allsum = int(sum(a))
    asum = 0

    for i in range(n):
        asum += a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def splittingplie(n , a):

    ans = 100000000000000000
    allsum = int(sum(a))
    asum = 0

    for i in range(n):
        asum += asum + a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def splittingplie(n , a):

    ans = 100000000000000
    allsum = sum(a)
    asum = 0

    for i in range(n):
        asum += asum + a[i]
        rldifference = abs(allsum - asum*2)
        ans = min(ans , rldifference)

    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def splittingplie(n , a):

    ans = 100000000000000
    sumlist = [0]*n

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

    for i in range(n):
        rldifference = abs(int(sumlist[i]) - (sumlist[-1] - sumlist[i]))
        ans = min(ans , rldifference)
    return ans

def main():
    n = int(input())
    a = list(map(int , input().split()))
    print(splittingplie(n , a))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in cumsum:
  mi = min(mi, abs(i - (su-i)))
print(mi)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

cumsum = list(accumulate(lst))

mi = 2 * 10 ** 9
su = cumsum[-1]
for i in cumsum:
  mi = min(mi, abs(su - 2 * i))
print(mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int,input().split())))
if L[0] < 0:
    L = [x-L[0] for x in L]
#print(L)
b = sum(L)//2
num = 0
for i in range(n):
    num += L[i]
    if num > b:
        c = sum(L[:i+1])-sum(L[i+1:])
        d = sum(L[:i])-sum(L[i:]) 
        #print(i,c,d)
        print(min(abs(c),abs(d)))
        break

Submission status: Wrong Answer

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

b = sum(L)//2
num = 0
for i in range(n):
    num += L[i]
    if num > b:
        c = sum(L[:i-1])-sum(L[i-1:])
        d = sum(L[:i])-sum(L[i:]) 
        #print(i,c,d)
        print(min(abs(c),abs(d)))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int,input().split())))
if L[0] < 0:
    L = [x-L[0] for x in L]
#print(L)
b = sum(L)//2
num = 0
for i in range(n):
    num += L[i]
    if num > b:
        c = sum(L[:i-1])-sum(L[i-1:])
        d = sum(L[:i])-sum(L[i:]) 
        #print(i,c,d)
        print(min(abs(c),abs(d)))
        break

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int,input().split())))
if L[0] < 0:
    L = [x-L[0] for x in L]
#print(L)
b = sum(L)//2
num = 0
for i in range(n):
    num += L[i]
    if num > b:
        c = sum(L[:i-1])-sum(L[i-1:])
        d = sum(L[:i])-sum(L[i:]) 
        #print(i,c,d)
        print(min(abs(c),abs(d)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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