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: Time Limit Exceeded

Solution code:
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


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

    ans = float("inf")
    S = sum(A)
    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            t = sum(A[:i])
            ans = min(ans, abs(S-2*t))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

Solution code:
#
# abc067 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
1 2 3 4 5 6"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
10 -10"""
        output = """20"""
        self.assertIO(input, output)


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

    ans = float("inf")
    if N == 2:
        ans = abs(A[0]-A[1])
    else:
        for i in range(1, N-1):
            ans = min(ans, abs(sum(A[:i])-sum(A[i:])))
    print(ans)


if __name__ == "__main__":
    # unittest.main()
	resolve()

Submission status: Time Limit Exceeded

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

cum_sum = 0
ans_lis = []

for i in range(0,N-1):
    cum_sum = cum_sum + A[i]
    score = abs(cum_sum - (sum(A)-cum_sum))

    ans_lis.append(score)

print(min(ans_lis))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

ans = INF
for i in range(N-1):
    x = sum(A[:i+1])
    y = sum(A[i+1:])

    tmp = abs(x - y)
    if tmp < ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

    total = sum(inlis)
    ans = 10 ** 20

    for i in range(n-1):
        x = sum(inlis[:i+1])
        y = total - x
        tmp = abs(x-y)
        if tmp < ans:
            ans = tmp

    print(ans)





if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

sum_a=sum(a)
ans = 10**11
for i in range(N-1):
    x = abs(sum_a - 2 * sum(a[:i+1]))
    if x<ans:
        ans=x


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=float('inf')
for i in range(1,n):
    m=min(m,abs(sum(l[:i])-sum(l[i:])))
print(m)

Submission status: Time Limit Exceeded

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

minint = 10**9

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

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

    print(minint)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
a_sum = a.sum()
#y = sum - x
ans = 10**15
for i in range(1,n):
    x = a[:i].sum()
    aa = abs(2 * x - a_sum)
    ans = min(ans,aa)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a_sum = sum(a)
#y = sum - x
ans = 10**15
for i in range(1,n):
    x = sum(a[:i])
    aa = abs(2 * x - a_sum)
    ans = min(ans,aa)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[7]:


ans = (10**9)*N
for i in range(1,N):
    x = sum(a[:i])
    y = sum(a[i:])
    ans = min(ans,abs(x-y))
    if ans < 2:
        break
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[7]:


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


# In[ ]:

Submission status: Time Limit Exceeded

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

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

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

ans = min(lst)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_li = list(map(int, input().split()))
# y = X - x
# |x - y| = |x - (X - x)|
#         = |-X + 2x|
total = sum(a_li)
ans = 10 ** 18
for i in range(1, N):
    ans = min(ans, abs(sum(a_li[:i]) * 2 - total))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
for i in range(N-1):
    b.append(abs(2*sum(a[:i+1])-sum_a))
print(min(b))

Submission status: Time Limit Exceeded

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

b = []
for i in range(N-1):
    b.append(abs(sum(a[:i+1])-sum(a[:i:-1])))
print(min(b))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

ans = abs(sum(a[1:])-a[0])
X = sum(a)

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = 10000000000
X = sum(a)

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = 10000000000
aa = sum(a)

for i in range(N-1):
    sum_a = sum(a[:i+1])
    sum_b = aa-sum_a
    sa = abs(sum_a-sum_b)
    ans = min(ans, sa)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 10000000000


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
ans = min([abs(sum(A)-2*a) for a in tmp])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]

ans = min([abs(sum(A)-2*a) for a in list(accumulate(A))[:len(A)-1]])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = None

for i in range(1, n):
  temp_1 = a[:i]
  temp_2 = a[i:]
  
  abs_num = abs(temp_1.sum() - temp_2.sum())

  if ans == None or ans > abs_num:
    ans = abs_num
else:
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
for i in range(1, n):
    ln.append(abs(z - 2 * sum(a[0: i])))
print(min(ln))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

total = sum(A)
ans = 10**9
if n > 2:
    for i in range(1,n-1):
        res = abs(total - 2*sum(A[:i]))
        ans = min(ans, res)
else:
    ans = (A[0] - A[1])
print(ans)

Submission status: Time Limit Exceeded

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

total = sum(A)
ans = 10**9
if n > 2:
    for i in range(1,n-1):
        res = abs(total - 2*sum(A[:i]))
        ans = min([ans, res])
else:
    ans = (A[0] - A[1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
b = sum(a)
ans = 10**100
for i in range(N-1):
    ans = min(ans,abs(sum(a[:i+1])*2-b))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
a = list(map(int,input().split()))
ruiseki = list(itertools.accumulate(a))
ans = 10**100
for i in range(N-1):
    ans = min(ans,abs(sum(a[:i+1])-sum(a[i+1:])))
print(ans)

Submission status: Time Limit Exceeded

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

def resolve():
    from itertools import accumulate

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

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans=10**18
    for i in range(1, N):
        snuke=B[i]
        araiguma=sum(A)-B[i]
        ans=min(ans,abs(snuke-araiguma))
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
s = a[:1]
t = a[1:]
x = sum(s)
y = sum(t)
if x-y==0:
  ans = 0
else:
  ans = abs(x-y)

for i in range(2,N):
  s = a[:i]
  t = a[i:]
  x = sum(s)
  y = sum(t)
  if x-y==0:
    ans = 0
    break
  elif abs(x-y)<ans:
    ans = abs(x-y)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
whole=sum(A)
answers=[]
for n in range(1,N):
    first=sum(A[:n])
    last=whole-first
    answers.append(abs(first-last))
print(min(answers))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
answers=[]
for n in range(1,N):
    first=sum(A[:n])
    last=sum(A[n:])
    answers.append(abs(first-last))
print(min(answers))

Submission status: Time Limit Exceeded

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

min_diff = float('inf')

for i in range(1, N):
  l_sum = sum(a[:i])
  r_sum = sum(a[i:])
  min_diff = min(min_diff, abs(l_sum - r_sum))

print(min_diff)

Submission status: Time Limit Exceeded

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

sal=sum(al)
res=10**9+1

for i in range(1,n):
    temp = al[:i]
    res = min(res,abs(sal/2-sum(temp)))

print(int(res*2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
min = float('inf')
for i in range(1,N):
    sunuke = a[:i]
    kuma = a[i:]
    if abs(sum(sunuke) - sum(kuma)) < min:
        min = abs(sum(sunuke) - sum(kuma))
print(min)

Submission status: Time Limit Exceeded

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

ans = 2*10**9

allsum = sum(a)

for n in range(1,N):
  ans_candidate = abs(2*sum(a[:n])- allsum)
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 2*10**9

for n in range(1,N):
  ans_candidate = abs(sum(a[:n])-sum(a[n:]))
  if ans > ans_candidate:
    ans = ans_candidate
    
print(ans)

Submission status: Time Limit Exceeded

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

min=1000000000000000
for i in range(n-1):
    xy=abs(sum(a[:i+1])-sum(a[i+1:]))
    if xy < min:
        min=xy
print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
s = sum(a)
print(min(abs(s - sum(a[:i])*2) for i in range(1, n)))

Submission status: Time Limit Exceeded

Solution code:
n, *a = map(int, open(0).read().split())
print(min(abs(sum(a) - sum(a[:i])*2) for i in range(1, n)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = 10**10
suma = sum(a)
for i in range(1, n):
    x = sum(a[:i])
    s = abs(x-(suma-x))
    if s < ans:
        ans = s
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = 10**10
for i in range(1, n):
    x = a[:i]
    y = a[i:]
    s = abs(sum(x)-sum(y))
    if s < ans:
        ans = s
print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = float('inf')
	for i in range(1, n):
		left = sum(a[:i])
		right = sum(a[i:])
		ans = min(ans, abs(left - right))
	print(ans)
resolve()

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(1,N):
    a = sum(A[:i])
    b = sum(A[i:])
    B.append(abs(a-b))
print(min(B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
       # coding: utf-8
    # Your code here!
    N = int(input())
    a = list(map(int,input().split()))
    print(min(abs(sum(a[0:i])-(sum(a)-sum(a[0:i]))) for i in range(1,N)))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
 
def main():
    N = int(input())
    a =list(map(int,input().split()))
    minit = []
    for i in range(1,N):
        b = abs(2*sum(a[0:i])-sum(a))
        minit.append(b)
        
    print(min(minit))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!


N = int(input())
a =list(map(int,input().split()))
minit = []
for i in range(1,N):
    b = abs(2*sum(a[0:i])-sum(a))
    minit.append(b)
    
print(min(minit))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a_sum = sum(a)

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

print(min(candidate))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
a = list(map(int,input().split()))
print(min(abs(sum(a[0:i])-(sum(a)-sum(a[0:i]))) for i in range(1,N)))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
a = list(map(int,input().split()))
b = list()
for i in range(1,N):
    element = abs(sum(a[0:i])-(sum(a)-sum(a[0:i])))
    b.append(element)
print(min(b))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
N = int(input())
a = list(map(int,input().split()))
b = list()
for i in range(1,N):
    element = abs(sum(a[0:i])-(sum(a)-sum(a[0:i])))
    b.append(element)
print(min(b))

Submission status: Time Limit Exceeded

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

total = sum(A)

ans = float("inf")
for i in range(1, N):
    cand = abs(2*sum(A[:i]) - total)
    ans = min(ans, cand)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = 10000000000000

for i in range(1,n):
  x = abs(sum(li[:i])-sum(li[i:]))
  if x < ans:
    ans = x

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
mn_list = []
for i in range(1,n):
    sunuke = sum(a[:i])
    araiguma = sum(a[i:])
    mn_list.append(abs(sunuke-araiguma))
print(min(mn_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
total = sum(a)
ans = float('inf')
for i in range(1,N):
    ans = min(abs(total-2*sum(a[:i])),ans)
print (ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

A_sum = sum(A)
ans = []

for k in range(1,N):
  S = sum(A[:k])
  T = A_sum-S
  ans.append(abs(S-T))

print(min(ans))

Submission status: Time Limit Exceeded

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

ans = []

for k in range(1,N):
  S = sum(A[:k])
  T = sum(A[k:])
  ans.append(abs(S-T))

print(min(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=n*(10**9)
for i in range(n-1):


    k=abs(  sum(a[0:i+1]) - sum(a[i+1:n]) )
    m=min(m,k)
print(m)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=n*10**9
for i in range(n-1):


    k=abs(  sum(a[0:i+1]) - sum(a[i+1:n]) )
    m=min(m,k)
print(m)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n=int(input())
a=list(map(int,input().split()))
#n=6
#a=[1,2,3,4,5,6]

if n==2:
    print(abs(a[1]-a[0]))
else:
#    for i in range(n):
#        if a[i]<0:
#            a[i]=-a[i]
#        else:
#            break
#    a.sort(reverse=True)
    asum=sum(a)
#    print("asum:",asum)
# itertools 使用 bit全探索
    xmin=asum
    for ip in itertools.product([0,1], repeat=n):
        xsum=sum([a[i] for i in range(len(ip)) if ip[i]==1])
#        xsum=0
#        for i in range(len(ip)):
#            if ip[i]==1:
#                xsum=xsum+a[i]
#        print("xsum:",xsum,ip)
        xmin=min(xmin,abs(asum-2*xsum)) 
    print(xmin)

Submission status: Time Limit Exceeded

Solution code:

import itertools

n=int(input())
a=list(map(int,input().split()))
#n=6
#a=[1,2,3,4,5,6]

if n==2:
    print(abs(a[1]-a[0]))
else:
    for i in range(n):
        if a[i]<0:
            a[i]=-a[i]
        else:
            break
    a.sort(reverse=True)
    asum=sum(a)
#    print("asum:",asum)
# itertools 使用 bit全探索
    xmin=asum
    for ip in itertools.product([0,1], repeat=n):
        xsum=sum([a[i] for i in range(len(ip)) if ip[i]==1])
#        xsum=0
#        for i in range(len(ip)):
#            if ip[i]==1:
#                xsum=xsum+a[i]
#        print("xsum:",xsum,ip)
        xmin=min(xmin,abs(asum-2*xsum)) 
    print(xmin)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    result = []

    for i in range(1, N):
        result.append(abs(sum(A[:i]) - sum(A[i:])))
    print(min(result))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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(1,N-1):
  x=sum(A[:i])
  y=sum(A[i:])
  if abs(x-y) < ans:
    ans = abs(x-y)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a =[int(i)  for i in input().split()]
b = sum(a) // 2
z = sum(a)
ans = 10**20

for i in range(1,n):
    c = sum(a[:i])
    d = z - c
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 10**20

for i in range(1,n):
    c = sum(a[:i])
    d = sum(a[i:])
    if abs(c-d) < ans:
        ans = abs(c-d)
    
print(ans)

Submission status: Time Limit Exceeded

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

X = sum(a)
x = list(sum(a[:i+1]) for i in range(n))
ans = min(list(abs(X-2*x[i]) for i in range(n-1)))

print(ans)