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:
N = int(input())
a = list(map(int, input().split()))

ans = 10 ** 20

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 = []
for x in range(1, n):
  y = n - x
  dis = abs(sum(a[:x]) - sum(a[x:]))
  ans.append(dis)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
sunuke=0
arai=0
ans=10**18
for i in range(1,n):
    sunuke=sum(a[:i])
    arai=s-sunuke
    t=abs(sunuke-arai)
    ans=min(t,ans)
print(ans)

Submission status: Time Limit Exceeded

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

x,y = 0,0
#a_L = list(sorted(a_L))
ans = float("inf")
g = sum(a_L)
for i in range(1,len(a_L)):
    x = sum(a_L[0:i])
    g = sum(a_L[i:])
    ans = min(abs(x-g),ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=input().split()
cards=[int(b) for b in a]
whole=sum(cards)
answers=[]
for c in range(N-1):
    sunuke=cards[:c+1]
    goukei=sum(sunuke)
    answers.append(abs(whole-goukei*2))
print(min(answers))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  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) 
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

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 = float("inf")

for i in range(1, N):
    if test(i):
        answer = abs(sum(A[:i]) - sum(A[i:]))

print(answer)

Submission status: Time Limit Exceeded

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 = []

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
sums = []
total = 0
for i in a:
    total += i
    sums.append(total)
sums.pop()
# print(sums)
ans = 2 * 10 ** 9 + 1
# print(sums)
for i in sums:
    ans = min(ans, abs(i - (sum(a) - i)))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def splittingplie(n , a):

    ans = 100000000000000

    for i in range(1 , n):
        rldifference = abs(sum(a[:i]) - sum(a[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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
cards = int(input())
cards_list = list(map(int, input().split()))

ans_list = []
sum_cards = sum(cards_list)

for i in range(1, cards):
    ans_list.append(abs(sum_cards - sum(cards_list[:i]*2 )))

print(min(ans_list))

Submission status: Time Limit Exceeded

Solution code:
cards = int(input())
cards_list = list(map(int, input().split()))

ans_list = []

for i in range(1, cards):
    ans_list.append(abs(sum(cards_list[:i]) - sum(cards_list[i:])))

print(min(ans_list))

Submission status: Time Limit Exceeded

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

#sum_a = sum(A)
x = 0
ans = 1000000000000000

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
#A = [i*(10**3) for i in range(N)]
#A = [i for i in range(N)]

#ans = abs(A[0]-sum(A[1:]))
#for i in range(2, math.ceil(N/2)):
        #ans = min(ans, abs(sum(A[:i])-sum(A[i:])))

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 100000000000
lix = []
for i in range(n-1):
    lix = li[:i+1]
    ans =min(ans ,abs(X - sum(lix)*2))
print(ans)

Submission status: Time Limit Exceeded

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

min = 0

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

    for j in range(i,n):
        all -= a[j]

    if i == 1:
        min = abs(all)
    else:
        if min > abs(all):
            min = abs(all)

print(min)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

a=[int(x) for x in input().split()]

min=50000000000

for i in range(N-1):
    sunuke=sum(a[0:i+1])
    arai=sum(a[i+1:N])
    if(abs(sunuke-arai)<=min):
        min=abs(sunuke-arai)

print(min)

Submission status: Time Limit Exceeded

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

Sc = list()

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

print(min(Sc))

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 abs(sum(a[:i])-sum(a[i:])) < ans:
        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()))
h=sum(a)
s=[]
for i in range(1,n):
  s.append(abs(h-sum(a[0:i])*2))
print(min(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
ans = float('Inf')
for i in range(1,n):
    x = sum(l[:i])
    j = abs(2*x - suml)
    ans = min(ans,j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
xs = set()
for i in range(2**n):
    x = []
    for j in range(n):
        if ((i >> j) & 1):
            x.append(l[j])
    xs.add(abs(2*sum(x) - suml))
try:
    xs.remove(0)
except:
    pass
ans = min(xs)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
xs = set()
for i in range(2**n):
    x = []
    for j in range(n):
        if ((i >> j) & 1):
            x.append(l[j])
    xs.add(sum(x))
xs.remove(0)
ans = float('Inf')
for i in xs:
    j = abs(2*i - suml)
    ans = min(ans,j)
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):
    if m > abs(sum(a[:i+1])-sum(a[i+1:])):
        m=abs(sum(a[:i+1])-sum(a[i+1:]))
print(m)

Submission status: Time Limit Exceeded

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


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
I = list(map(int, input().split()))
minX = 10000000000
end = I.pop() 
for i in range(len(I)):
  minX = min(minX, abs(sum(I) - end ) )
  end += I.pop() 
  
print(minX)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans = 100 ** 100

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans_list = [0] * (N - 1)

for i in range(1, N):
    x = sum(a[:i])
    ans_list[i - 1] = abs(A - 2 * x)

print(min(ans_list))

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:
#!/usr/bin/env python3
import math

N = int(input().split()[0])
a_list = list(map(int, input().split()))

total = sum(a_list)
work_list = []

for i in range(N - 1):
    sunuke = sum(a_list[: i + 1])
    arai = total - sunuke
    work_list.append(abs(sunuke - arai))

ans = min(work_list)
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 = sum(A[:i])
    y = sum(A[i:])
    d = abs(x-y)
    ans = min(ans, d)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [float('inf')] * n
    for i in range(1, n):
        ans[i] = abs(sum(a[:i])-sum(a[i:]))

    print(min(ans))


if __name__ == '__main__':
    main()

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

Submission status: Time Limit Exceeded

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

print(min_v)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l = list(map(int,input().split()))
#print(l,l[:1],l[1:])
ans = []
for i in range(1,N):
  #print(sum(l[:i]),sum(l[i:]))
  dif = abs(sum(l[:i])-sum(l[i:]))
  ans.append(dif)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

*A,  = map(int, input().split())
A    = np.array(A)
min = float('INF')

for i in range(N-1):

    min_temp = (np.abs(np.sum(A)-2*np.sum(A[0:i+1])))
    if min_temp < min:
        min = min_temp

print(min)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

*A,  = map(int, input().split())
A    = np.array(A)
min = float('INF')

for i in range(N-1):

    min_temp = (np.abs(np.sum(A[0:i+1])-np.sum(A[i+1:N])))

    if min_temp < min:
        min = min_temp

print(min)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

*A,  = map(int, input().split())
A    = np.array(A)
min = float('INF')

for i in range(N-1):
    sunek = A[0:i+1]
    araig = A[i+1:N]
    min_temp = (np.abs(np.sum(sunek)-np.sum(araig)))

    if min_temp < min:
        min = min_temp

print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

*A,  = map(int, input().split())


min = float('INF')

for i in range(N-1):
    sunek = A[0:i+1]
    araig = A[i+1:N]
    min_temp = (abs(sum(sunek)-sum(araig)))

    if min_temp < min:
        min = min_temp

print(min)

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):
    x = sum(a[:i])
    y = sum(a[i:])
    check = abs(x - y)
    if ans > check:
        ans = check

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in 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**100
for i in range(1,n):
  x=a[:i]
  y=a[i:]
  ans=min(ans,abs(sum(x)-sum(y)))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np
import sys
input = sys.stdin.readline


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

    SUM = sum(a)

    ans = list()
    for i in range(1, n):
        ans.append(abs(2 * sum(a[:i]) - SUM))

    print(min(ans))


if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
minxy = 1000000000000000000
for i in range(1,n):
    s1 = sum(a[0:i])
    s2 = sum(a[i:n])
    minxy = min(minxy,abs(s1-s2))
print(minxy)

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:
# -*- coding: utf-8 -*-

def main(N,A):
    zenbu = sum(A)
    ans = float("INF")
    for i in range(1,N):
        part_sum = 0
        part_sum = sum(A[:i])
        ans = min(ans, abs(zenbu-2*part_sum))
    print(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    

    ans = float("inf")
    
    if N == 2:
        print(abs(A[0] - A[1]))
        sys.exit()
    
    for i in range(1, N-1):
        sunuke = 0
        araiguma = 0
        
        for j, val in enumerate(A):
            if i >= j:
                sunuke += val
            else:
                araiguma += val
                
        tmp = abs(sunuke-araiguma)
        if ans > tmp:
            ans = tmp
            
    print(ans)
        
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

sum_a = sum(a)

lis = [sum_a]

for i in range(n-1):
    lis.append(abs(sum_a - 2 * sum(a[:i+1])))

print(min(lis[1:]))

Submission status: Time Limit Exceeded

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

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

    print(min_diff)

main()

Submission status: Time Limit Exceeded

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

    min_diff = float('inf')
    for i in range(1,N):
        if min_diff > abs(sum(a[i:])-sum(a[:i])):
            min_diff = abs(sum(a[i:])-sum(a[:i]))

    print(min_diff)

main()

Submission status: Time Limit Exceeded

Solution code:
# ABC067-C
N = int(input())
a = list(map(int, input().split()))
a_sum = sum(a)
x = 0
y = 0
diff = []
for i in range(0, N-1):
    x_a = a[0:i+1]
    x = sum(x_a)
    y = a_sum - x
    diff.append(abs(x-y))
print(min(diff))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

dif_list = []
for i in range(1,N,1):
  sunuke = sum(card[:i])
  arai = sum(card[i:])
  dif = abs(sunuke-arai)
  dif_list.append(dif)
  
print(min(dif_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = 0
ABS = 0
min = -1
loop = 0
SUM = 0
for i in range(N):
    SUM += a[i]

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

print(min)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(min)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(min)

Submission status: Time Limit Exceeded

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

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

print(min)

Submission status: Time Limit Exceeded

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

def main():
    ans = float('inf')
    for i in range(N - 1):
        A[i] *= -1
        ans = min(ans, abs(sum(A)))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    ans = float('inf')
    for i in range(1, N):
        ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


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

minute = sys.maxsize

for i in range(1, N):
    # すぬけくんとアライグマのカードの総和の差の絶対値
    tmp = abs(sum(a[:i]) - sum(a[i:]))
    if tmp < minute:
        minute = tmp
print(minute)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst_a = list(map(int, input().split()))
total = sum(lst_a)
ans = float("INF")


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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst_a = list(map(int, input().split()))
ans = float("INF")


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


print(ans)

Submission status: Time Limit Exceeded

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

ans = 10**20
for i in range(N-1):
    p = abs(sum(A[:i+1])-sum(A[i+1:]))
    if ans > p:
        ans = p
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
res = []
for i in range(1,len(a)):
    res.append(abs(sum(a[:i])-sum(a[i:])))

print(min(res))

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

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

sum_a = sum(a)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
x = 0
for i in range(N-1):
    x+=A[i]
    ans = min(ans, abs(sum(A)-2*x))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10**10
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:
N = int(input())
A = list(map(int, input().split()))
tmp = 0
diffs = []
for i in range(N - 1):
    tmp += A[i]
    diffs.append(abs(sum(A) - tmp - tmp))
print(min(diffs))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())
lst = list(map(int,input().split()))
ans = float('inf')
for i in range(N-1):
    #print(sum(lst[:i+1]) , sum(lst[i+1:]))
    ans = min(ans,math.fabs(sum(lst[:i+1]) - sum(lst[i+1:])))
print(int(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(n-1):
  x = sum(a[:i+1])
  y = total - x
  if(abs(x-y) < ans):
    ans = abs(x-y)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product
import numpy as np

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A)

    total = sum(A)
    ans = float('inf')
    for pos in product(range(2), repeat=N):
        if len(set(pos)) == 1:
            continue

        x = np.array(pos)
        X = np.sum(A * x)
        Y = total - X
        ans = min(ans, abs(X - Y))

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

X = sum(a)
x = sum(a[:1])

minsum = 10000000000

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

print(minsum)

Submission status: Time Limit Exceeded

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

X = sum(a)
x = sum(a[:1])

minsum = 10000000000

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

print(minsum)

Submission status: Time Limit Exceeded

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

import numpy
res = numpy.cumsum(A)

ans = 10 ** 18
for i in range(N-1):
    x = res[i]
    ans = min(abs(x - (sum(A)-x)), ans)
print(ans)

Submission status: Time Limit Exceeded

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

ans = 10 ** 18
for i in range(1,N):
#     print("すぬけ",A[0:i])
#     print("アライグマ",A[i:N])
    x = sum(A[0:i])
    y = sum(A[i:N])
    ans = min(abs(x - y), ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a =[int(_) for _ in input().split()]
ans = 10**15
cardsum = sum(a)

for i in range(N-1):
    snuke = sum(a[:i+1])
    arai = cardsum - snuke
    diff = abs(snuke - arai)
    if diff < ans:
        ans = diff

print(ans)

Submission status: Time Limit Exceeded

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