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:
import bisect
ans = float('inf')
n = int(input())
a = list(map(int, input().split()))
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())

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

sm = sum(li_a)
result = -1
for c in range(1, len(li_a)):
    x = sum(li_a[0:c])
    a = abs(sm - 2 * x)
    result = min(result, a) if result >= 0 else a

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

sm = sum(li_a)
result = -1
for c in range(1, len(li_a)):
    x = sum(li_a[0:c])
    y = sm - x
    result = min(result, abs(x - y)) if result >= 0 else abs(x - y)

print(result)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = input().split()
sum0 = 0

for i in range(N):
  a[i] = int(a[i])
  sum0 += a[i]

for i in range(N-1):
  if(i == 0):
   b = a[0]
   min = abs(2*b-sum0)
  elif(1<=i<=int(N/2)-1):
   b = a[:i+1]
   #print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  else:
   b = a[i+1:]
   #print(b)
   tmp = abs(2*sum(b)-sum0)
   if(min > tmp):
      min = tmp
  #print(min)
print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = input().split()
sum = 0
sum_sunuke = 0

def sum_list(L):
  sum = 0
  for i in range(len(L)):
   sum += L[i]
  return sum

for i in range(N):
  a[i] = int(a[i])
  sum += a[i]

for i in range(N-1):
  #print(a[:i+1])
  #print(a[i+1:])
  if(i == 0):
   min = abs(2*sum_list(a[:i+1])-sum)
  else:
   tmp = abs(2*sum_list(a[:i+1])-sum)
   if(min > tmp):
      min = tmp
  #print(min)
print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = float("inf")
s = sum(a)
for i in range(1,n):
  if ans > abs(sum(a[:i])*2 - s):
    ans = abs(sum(a[:i])*2 - s)
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):
  if ans > abs(sum(a[:i]) - sum(a[i:])):
    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 = 2*10**9
X = sum(a)
for i in range(n-1):
    x = sum(a[:i+1])
    ans = min(ans,abs(X-x*2))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 2*10**9
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:
from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

ans = 10**100
for i in range(1, n):
    if ans>abs(sum(a[:i])-sum(a[i:])):
        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()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = 0
    for j in range(i+1):
        suma+=a[j]
    kari = abs(SUM-2*suma)
    MIN = min(MIN,kari)
print(MIN)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = sum(a[:i+1])
    sumb = SUM-suma
    kari = abs(suma-sumb)
    MIN = min(MIN,kari)
print(MIN)

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()))
num = []
for i in range(1,N):
  num.append(abs(sum(A[:i]) - sum(A[i:])))
print(min(num))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
l = list(map(int, input().split()))
nl = np.array(l)
X = nl.sum()
a = []
for i in range(N-1):
    x = nl[0:i+1]
    a.append(abs(2 * x.sum() - X))
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
l = list(map(int, input().split()))
nl = np.array(l)
a = []
for i in range(N-1):
    x = nl[0:i+1]
    y = nl[i+1:N]
    a.append(abs(x.sum() - y.sum()))
print(min(a))

Submission status: Time Limit Exceeded

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)
for i in range(1,n):
  ans=abs(2*sum(a[:i])-suma)
  if ans < minans:
    minans = ans
    
print(minans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)

absa=[abs(i) for i in a]
minans=sum(absa)

for x in range(1,n):
  valx=0
  for i in range(x):
    valx+=a[i]
  
  valy=0
  for j in range(x,n):
    valy+=a[j]

  ans=abs(valx-valy)

  if ans < minans:
    minans=ans
    
print(minans)

Submission status: Time Limit Exceeded

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

s = sum(a)

ans = float('inf')
for i in range(n-1):
    x = sum(a[:i+1])
    ans = min(ans, abs(s-2*x))

print(ans)

Submission status: Time Limit Exceeded

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]=abs(sum(number[:i+1])*2-SUM)

print(min(number_sum))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
As = list(map(int, input().split()))
sunuke = 0
anslist = []

for i in range(n-1):
  sunuke += As[i]
  arai = sum(As) - sunuke
  
  anslist.append(abs(sunuke-arai))

print(min(anslist))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
ANS = []
for i in range(N-1) :
    p = abs(sum(L[:i+1])-sum(L[i+1:]))
    ANS.append(p)
print(min(ANS))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int, input().strip().split(' ')))
arrayX=[]
for i in range(N):
  if i == 0:
    pass
  else:
    array1 = array[:i]
    array2 = array[i:]
    n1 = sum(array1)
    n2 = sum(array2)
    num = abs(n1-n2)
    arrayX.append(num)
arrayY=sorted(arrayX)
print(arrayY[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
tmp = 10 ** 12

for i in range(1,N):
    if abs(sum(L[:i]) - sum(L[i:])) < tmp:
        tmp =  abs(sum(L[:i]) - sum(L[i:]))
print(tmp)

Submission status: Time Limit Exceeded

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

l = []
X = sum(a)
for i in range(N-1):
	x = sum(a[:i+1])
	l.append(abs(X - 2 * x))

print(min(l))

Submission status: Time Limit Exceeded

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

l = []
for i in range(N-1):
	x = sum(a[:i+1])
	y = sum(a) - x
	l.append(abs(x-y))

print(min(l))

Submission status: Time Limit Exceeded

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

sunuke_l = []
sunuke = 0
arai_l = []
arai = 0
all_sum = sum(a)
diff_l = []
for i in range(1,N):
    sunuke = sum(a[0:i])
    arai = all_sum - sunuke
    diff_l.append(abs(sunuke - arai))

print(min(diff_l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans  =2*10**9
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())
L = list(map(int,input().split()))
S = sum(L)
A = []
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
  A.append(p)
print(min(A))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
S = sum(L)
A = [abs(2*sum(L[0:1])-S)]
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
  if (p <= A[0]):
    del A[0]
    A.append(p)
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
res = []
for i in range(1, N-1):
    snk = sum(A[:i])
    arg = sum(A[i:])
    res.append(abs(snk-arg))
if N == 2:
    print(abs(A[0] - A[1]))
else:
    print(min(res))

Submission status: Time Limit Exceeded

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

a_sum = sum(a_list)
min_num = float("inf")

for i in range(1, N):
    x = sum(a_list[:i])
    y = a_sum - x
    if min_num >= abs(x-y):
        min_num = abs(x-y)
print(min_num)

Submission status: Time Limit Exceeded

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

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

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cum_sum = [sum(A[:i+1]) for i in range(len(A))]
b = cum_sum[-1]

ans = float("inf")

for a in cum_sum[:-1]:
    ans = min(ans, abs(2 * a - b))

print(ans)

Submission status: Time Limit Exceeded

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

sum_a = [sum(a[0:i]) for i in range(1, N)]
a.reverse()
sum_b = [sum(a[0:i]) for i in range(1, N)]

res = abs(sum_a[0] - sum_b[N-2])
for i in range(N-1):
  res = min(res, abs(sum_a[i] - sum_b[N-2-i]))
  
print(res)

Submission status: Time Limit Exceeded

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

res = abs(sum(a[0:1]) - sum(a[1:]))
for i in range(2, N-1):
  temp_a = sum(a[0:i])
  temp_b = sum(a[i:])
  if abs(temp_a - temp_b) < res:
  	res = abs(temp_a - temp_b)
print(res)

Submission status: Time Limit Exceeded

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

mindiff = 10 ** 9 * 2 * 10 ** 5 + 1
for i in range(N-1):
    s1 = sum(a[0:i + 1])
    s2 = sum(a[i+1:])
    mindiff = min(mindiff, abs(s1 - s2))
    
print(mindiff)

Submission status: Time Limit Exceeded

Solution code:
# vim: set fileencoding=utf-8 :
n = int(raw_input())
a = map(int, raw_input().split())

diff = None
min_diff = 999999999999999999

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

print(min_diff)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sum_A = sum(A)
ans = abs(2 * A[0] - sum_A)

for i in range(1, N - 1):
    temp = 0
    for j in range(i):
        temp += A[j]
    temp = abs(2 * temp - sum_A)
    if temp < ans:
        ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
if N == 2:
    print(abs(a[1]-a[0]))
    exit()
S = sum(a)
m = float('inf')
for i in range(N-2):
    m = min(abs(S - sum(a[:i+1])*2),m)
    if m == 0:
        break
print(m)

Submission status: Time Limit Exceeded

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

s = sum(a)
ans = float('inf')
for i in range(1, n):
    if abs(s-sum(a[:i])*2) < ans:
        ans = abs(s-sum(a[:i])*2)

print(ans)

Submission status: Time Limit Exceeded

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

s = sum(a)
ans = float('inf')
for i in range(1, n):
    x = sum(a[:i])
    y = s - x
    if abs(x-y) < ans:
        ans = abs(x-y)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def m():
    n = int(input())
    a = list(map(int, input().split()))
    s = a.copy()

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

    ans = 999999999999
    for j in range(1, n):
        ans = min(ans, abs(sum(s[:j]) - sum(s[j:])))
    return ans
print(m())

Submission status: Time Limit Exceeded

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

print(tmp)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C

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

    # See:
    # https://atcoder.jp/img/arc078/editorial.pdf
    total_a = sum(a)
    diff = float('inf')

    for i in range(1, n):
        diff = min(diff, abs(total_a - 2 * sum(a[:i])))

    print(diff)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
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(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
mi=10**15
for i in range(1,len(a)):
  s1=sum(a[0:i])
  s2=s-s1
  #print(s1,s2)
  mi=min([mi,abs(s1-s2)])
print(mi)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
m=float("inf") 

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans=[]

for i in range(1,n):
    snuke=sum(a[0:i])
    raccoon=sum(a)-snuke
    ans.append(abs(snuke-raccoon))

print(min(ans))

Submission status: Time Limit Exceeded

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

ans=[]

for i in range(1,n):
    snuke=sum(a[0:i])
    raccoon=sum(a[i:])
    ans.append(abs(snuke-raccoon))

print(min(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_sum=sum(a)
array=[]
for i in range(n-1):
    k=sum(a[0:i+1])
    array.append(k)
array_i=[]
for i in range(n-1):
    m=abs(a_sum-(2*array[i]))
    array_i.append(m)
print(min(array_i))

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(abs(sum(a[:i])-sum(a[i:])), ans)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def solve():  # 068C - Splitting Pile
    N = int(input())
    a = [int(x) for x in input().split(" ")]
    X = sum(a)
    min_sum = 2 * 1e10

    for i in range(N - 1):
        if abs(X - 2 * sum(a[:i + 1])) < min_sum:
            min_sum = abs(X - 2 * sum(a[:i + 1]))
    print(min_sum)


solve()

Submission status: Time Limit Exceeded

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

d = []

for i in range(1, n):
    d.append(abs(sum(a[:i]) - sum(a[i:])))

print(min(d))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def Q3(x):
    N = x[0][0]
    lst = x[1][:]
    absolute = float('inf')
    allsum = sum(lst)
    for k in range(1, N):
        sunuke = sum(lst[:k])
        a = abs(allsum - sunuke * 2)
        if a < absolute:
            absolute = a
    return absolute

l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
n = [l,m]
print(Q3(n))

Submission status: Time Limit Exceeded

Solution code:
def Q3(x):
    N = x[0][0]
    lst = x[1][:]
    absolute = float('inf')
    for k in range(1, N):
        sunuke = sum(lst[:k])
        arai = sum(lst[k:])
        a = abs(sunuke - arai)
        if a < absolute:
            absolute = a
    return absolute

l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
n = [l,m]
print(Q3(n))

Submission status: Time Limit Exceeded

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

n = raw_input()
n = int(n)

a = raw_input()
a = a.split()
a = map(int,a)

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

i = 1
while i < n - 1:
    tmp = abs(sum(a[:i]) - sum(a[i:]))
    if  tmp <= score:
        score = tmp
    i += 1

print score

Submission status: Time Limit Exceeded

Solution code:
def splitting_pile():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	ans = abs(sum(nums[:1])-sum(nums[1:]))
	for i in range(1, n):
		ans = min(ans, abs(sum(nums[:i])-sum(nums[i:])))
	print ans


if __name__ == "__main__":
	splitting_pile()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Here your code !
N=int(input())
b=input()
c=b.split(" ")
d=map(int,c)
a=list(d)
X=sum(a)
ans=[]
for i in range(N-1):
    A=abs(X-2*sum(a[0:i+1]))
    ans.append(A)
ans1=min(ans)
print(ans1)

Submission status: Time Limit Exceeded

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

sum_a =  sum(a)

minv = abs(2*sum(a[:1]) - sum_a)

for i in range(1, N-1):
    tmp = abs(2*sum(a[:i+1]) - sum_a)
#     print(tmp)
    
    if minv > tmp:
        minv = tmp
        
print(minv)

Submission status: Time Limit Exceeded

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

ans = 99999999999999999

for i in range(len(a)-1):
    tmp = abs(sum(a[:i+1]) - sum(a[i+1:]))
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

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

Sum = sum(a[0:])
temp = abs(Sum-2*a[0])
for i in range(1,N-1,1):
    temp1 = abs(Sum-2*sum(a[0:i]))
    if temp1 < temp:
        temp = temp1
print(temp)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
def solution(a):
    for i in xrange(1, len(a)):
        ab = abs(sum(a[:i]) - sum(a[i:]))
        if i == 1:
            Min = ab 
            continue
        if ab < Min:
            Min = ab
    print Min
N = int(raw_input())
a = map( int, raw_input().split())
solution(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

min_a = 999999999999999
for i in range(1, len(a)):
    cal = abs(sum(a[:i]) - sum(a[i:]))
    if cal < min_a:
        min_a = cal
print(min_a)

Submission status: Time Limit Exceeded

Solution code:
#Python

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


b=[]
for i in range(N-1):
	i=i+1
	#print "x::"+str(sum(a[:i]))
	#print "sum-2x::"+str( abs( sum(a) - sum(a[:i])*2 ) )
	b.append( abs( sum(a) - sum(a[:i])*2 ) )

#print b
print min(b)

Submission status: Time Limit Exceeded

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

for i in range(1,n):
    a = sum(num_list[:i])
    b = sum(num_list[i:])
    if abs(a-b) < dis:
        dis = abs(a-b)

print(dis)

Submission status: Time Limit Exceeded

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

for i in range(1,n):
    a = sum(num_list[:i])
    b = sum(num_list[i:])
    dis.append(abs(a-b))

print(min(dis))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8

def main():
	N = int(input())
	cards = list(map(int, input().split()))
	sum_cards = sum(cards)
	if N == 2:
		print(abs(cards[0] - cards[1]))
	else:
		out = min([abs(sum_cards - 2 * sum(cards[0:i])) for i in range(1, N-1)])
		print(out)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

print(min(abs(sum(a[:i]) - sum(a[i:])) for i in range(1, n)))

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8

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

	if N == 2:
		print(abs(cards[0] - cards[1]))
	else:
		print(min([abs(calcDif(cards, x)) for x in range(1, N - 1)]))


def calcDif(cards, k):
	# k >= 1
	#print(k)
	x = cards[:k]
	y = cards[k:len(cards)]
	return(sum(x) - sum(y))

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

min_diff = abs(sum(a_list[:1]) - sum(a_list[1:]))
for i in range(2, N):
    diff = abs(sum(a_list[:i]) - sum(a_list[i:]))
    min_diff = min(min_diff, diff)
print(min_diff)

Submission status: Time Limit Exceeded

Solution code:
if __name__=='__main__':
    alls = int(input())
    num_src = input().split(' ')
    num_cards = []
    ans = 0
    for i in num_src:
        num_cards.append(int(i))
        ans += abs(int(i))
    x = 0
    y = 0
    for i in range(0,alls-1):
        x=0
        y=0
        for j in range(0,alls):
            if j <= i:
                x += num_cards[j]
            else:
                y += num_cards[j]
        if y<x:
            tmp = abs(x-y)
        else:
            tmp = abs(y-x)
        if tmp < ans:
            ans = tmp
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input().strip())
    a = list(map(int, input().strip().split()))
    min_v = float("inf")
    for i in range(1, N):
        x = sum(a[:i])
        y = sum(a[i:])
        min_v = min(min_v, abs(x - y))
    print(min_v)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#Python

N = input()

#print N

a = map(int, raw_input().split())
#print a
#print sum(a)

b=[]

for i in range(N-1):
	i=i+1
	#print "g1::"+str(sum(a[:i]))
	#print "g2::"+str(sum(a[i:]))
	#print "sa::"+str( abs(sum(a[:i]) - sum(a[i:])) )
	b.append( abs(sum(a[:i]) - sum(a[i:])) )

#print b
print min(b)

Submission status: Time Limit Exceeded

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

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

SUM_CARD = sum(a)

i=1

diff_sum = 0
sunuke = sum(a[0:i])
diff_sum = abs(sunuke*2-SUM_CARD)
i+=1

while(i<N):
    sunuke = sum(a[0:i])
    diff_sum_new = abs(sunuke*2-SUM_CARD)
    if diff_sum_new<diff_sum:
        diff_sum = diff_sum_new
    i += 1

print(diff_sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

if(__name__ == "__main__"):
    N = int(input())
    a = [int(i) for i in input().split()]
    #print(a,b)
    
    #print(maxlist)
    sunuke = a[:1]
    arai = a[1:]
    darai = deque(arai)
    #print(sunuke)
    #print(darai)
    distmin = abs(sum(sunuke) - sum(darai))
    
    for i in range(1,N-1):
        sunuke.append(a[i])
        darai.popleft()
        #print(sunuke)
        #print(darai)
        dist = abs(sum(sunuke) - sum(darai))
        if(distmin > dist):
            distmin = dist
    
    print(distmin)

Submission status: Time Limit Exceeded

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

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

print(min(ans))

Submission status: Time Limit Exceeded

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

diff = [abs(sum(a[select:])-sum(a[:select])) for select in range(1,N)]
print min(diff)

Submission status: Time Limit Exceeded

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

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

ls = []

for i in range(1, N):
    A = sum(ax[:i])
    B = sum(ax[i:])
    ls.append(abs(A-B))

print(sorted(ls)[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

s = [abs(sum(a[:i+1])-sum(a[i+1:])) for i in range(N-2)] 
if len(a)==2:
    print(abs(a[0]-a[1]))
else:
    print(min(s))

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
card = input().split(' ')
card = [int(s) for s in card]
min_s = 1000000000000
for i in range(n -1):
    if abs(sum(card[:i+1]) - sum(card[i+1:])) < min_s:
        min_s= abs(sum(card[:i+1]) - sum(card[i+1:]))
    
print(min_s)