qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
input = input().split()

n = s[0]
k = s[1]

if n ==1 :
    print(0)
else:
    print(n-k)

# Fixed code:
s = input().split()

n = int(s[0])
k = int(s[1])

if k==1 :
    print(0)
else:
    print(n-k)
# Buggy code:
N, K = map(int, input().split(" "))

if K == 1:
    print(N)
    exit(0)
    
    
ans = N - K
print(ans)

# Fixed code:
N,K =map(int,input().split())
ans =int(0)

if K==1:
    print(ans)
    exit()

else:
    ans = N - K

print(ans)
# Buggy code:
n,k=map(int,input().split())
if k=1:
 print("0")
else:
print(n-k) 

# Fixed code:
n,k = map(int, input().split(' '))
if k <= 1:
  ans = 0
else:
  ans = n - (k-1) - 1
print(ans)
# Buggy code:
N, K = map(int, input().split())
if N==1:
    print(0)
else:
    print(N-K)

# Fixed code:
N,K = map(int,input().split())
if K == 1:
    ans = 0
else:
    ans = N - K
print(ans)
# Buggy code:
n,k = map(int,input().split())

mi = 1
ma = 1 + k-n

if(k==1):
    print(0)
else:
    print(ma-mi)

# Fixed code:
n,k = map(int,input().split())

mi = 1
ma = 1 + n-k

if(k==1):
    print(0)
else:
    print(ma-mi)
# Buggy code:

data = []

data.extend(list(map(int, input().split(str))))
N = data[0]
K = data[1]

if K == 1:
    print(0)
else:
    print(K - N)

# Fixed code:
data = []

data.extend(list(map(int, input().split(" "))))
N = data[0]
K = data[1]

if K == 1:
    print(0)
else:
    print(N - K)
# Buggy code:
#!/usr/bin/python3

def main():
  n, k = map(int, input().split(' '))
  if k == 1:
    print(n)
    return

  print(n - k)
  return

if __name__ == '__main__':
  main()

# Fixed code:
#!/usr/bin/python3

def main():
  n, k = map(int, input().split(' '))
  if k == 1:
    print(0)
    return

  print(n - k)
  return

if __name__ == '__main__':
  main()
# Buggy code:
n,k= [int(i) for i in input().split()]
if k==1:
    return 0
else:
    return n-k

# Fixed code:
n,k = [int(i) for i in input().split()]

if k == 1:
    print(0)
else:
    print(n-k)
# Buggy code:
n,k=(int(i) for i in input().split())
if n>=k:
  print(n-k)
else:
  print(0)

# Fixed code:
n,k = (int(i) for i in input().split())
if k == 1:
    print(0)
else:
    print(n-k)
# Buggy code:
N, K = map(int, input().split())
if N == 1:
    print(0)
else:
    print(N - K + 1 - 1)

# Fixed code:
N, K = map(int, input().split())
if K == 1:
    print(0)
else:
    max = N-K+1
    print(max-1)
# Buggy code:
N, K = (int(i) for i in input().split())

if K>=N:
    ans = 0
else:
    ans=N-K
print(ans)

# Fixed code:
N, K = (int(i) for i in input().split())

if K == 1:
  ans = 0
else:
  ans = N-K

print(ans)
# Buggy code:
x,y=map(int,input().split())
if y == 1:
  print(x)
else:
  print(x-y)

# Fixed code:
x,y = map(int,input().split())

if(y==1):
  print(0)
else:
  print(x-y)
# Buggy code:
N, K = map(int, input().split())
ans = N - K
ans = ans if K == 1 else 0
print(ans)

# Fixed code:
N, K = map(int, input().split())
ans = N - K if K > 1 else 0
print(ans)
# Buggy code:
s = list(map(int, input().split()))
if (s[1] == 1:
    ans = s[0] - s[1]
    print(ans)
else:
    print(0)

# Fixed code:
s = list(map(int, input().split()))
if (s[1] != 1):
    ans = s[0] - s[1]
    print(ans)
else:
    print(0)
# Buggy code:
N, K = map(int,input().split())
if N != 1:
    print(N-K)
else:
    print(0)

# Fixed code:
N,K=map(int,input().split())
if K!=1:
  ans=N-K
else:
  ans=0
print(ans)
# Buggy code:
x,y=map(int,input().split())
if y = 1:
  print(0)
else:
  print(x-y)

# Fixed code:
x,y = map(int,input().split())	

if(y==1):
    ans=0
else:
    ans=x-y

print(ans)
# Buggy code:
splited = input().split(' ')
N = int(splited[0])
K = int(splited[1])

if(K == 1):
    return 0
else
    return N - K

# Fixed code:
splited = input().split(' ')
N = int(splited[0])
K = int(splited[1])
 
if(K == 1):
    print(0)
else:
    print(N - K)
# Buggy code:
from sys import stdin
l = stdin.readline().rstrip().split()

n = int(l[0])
k=int(l[1])

if k == 1:
    print 0;
else:
    print n-k

# Fixed code:
from sys import stdin
l = stdin.readline().rstrip().split()

n = int(l[0])
k=int(l[1])

if k == 1:
    print(0)
else:
    print(n-k)
# Buggy code:
n, k = map(int, input().split())
print([0, 0, n-k][k!=1])

# Fixed code:
n,k=map(int,input().split())
print([n-k,0][k==1])
# Buggy code:
N,K=map(int,input().split())
print(0 if K==1 or K==N else N-K+1)

# Fixed code:
N, K = map(int, input().split())
print(0 if N == K or K == 1 else N - K)
# Buggy code:
N, K = (int(i) for i in input().split())

if K=1:
    ans=0
else:
    ans=N-K
print(ans)

# Fixed code:
N, K = (int(i) for i in input().split())

if K == 1:
    print(0)
else:
    print(N-K)
# Buggy code:
n, k = map(int, input().split())
rem = n-k
if n == 1:
    print(0)
    exit()
print(rem)

# Fixed code:
n, k = map(int, input().split())
if k == 1:
    print(0)
    exit()
print(n-k)
# Buggy code:
N, K = map(int, input().split())

if K == 1:
    print(N)
else:
    print(N - K)




# Fixed code:
N,K = map(int,input().split())
if K==1:
    print(0)
else:
    print(N-K)
# Buggy code:
class BallDistribution:
    def __init__(self):
        self.N, self.K = map(int, input().split())

    def max_number(self):
        if self.K == 1:
            print(0)

        print(self.N - self.K)


ballDistribution = BallDistribution()
ballDistribution.max_number()


# Fixed code:
class BallDistribution:
    def __init__(self):
        self.N, self.K = map(int, input().split())

    def max_number(self):
        if self.K == 1:
            print(0)
        else:
            print(self.N - self.K)


ballDistribution = BallDistribution()
ballDistribution.max_number()
# Buggy code:
a = input().split()
a = [int(i) for i in a]
if a[1] == 0:
  print(0)
else:
  print(a[0]-a[1])

# Fixed code:
a,b=[int(i) for i in input().split()]
if b==1:
  print(0)
else:
  print(a-b)
# Buggy code:
a,b=map(int,input().split())
if b==1:print(0)
else:print(b-a)


# Fixed code:
(a, b) = input().split()
a = int(a)
b = int(b)
if b == 1:
	print(0)
else:
	print(a - b)
# Buggy code:
s = input().split()

k = int(s[0])
n = int(s[1])

if n ==1 :
    print(0)
else:
    print(n-k)

# Fixed code:
s = input().split(" ");
n = int(s[0]);
k = int(s[1]);
if k == 1 :
	print(0);
else :
	print(n-k);
# Buggy code:
n,k=map(int,input().split())
print(n-k if n!=1 else 0)

# Fixed code:
n,k=map(int,input().split());print(n-k if k!=1 else 0)
# Buggy code:
import numpy as np

N = int(input())
W = input().split()

for i in range(N):
    W[i] = int(W[i])
min_w= 100000
for i in range(N-1):
    w1 = W[:i]
    w2 = W[i+1:N-1]
    w1 = np.array(w1)
    w2 = np.array(w2)
    min_w = min(min_w, abs(np.sum(w2)-np.sum(w1)))

print(min_w)

# Fixed code:
import numpy as np

N = int(input())
W = input().split()

for i in range(N):
    W[i] = int(W[i])
min_w= 1000000
for i in range(N-1):
    w1 = W[:i+1]
    w2 = W[i+1:]
    w1 = np.array(w1)
    w2 = np.array(w2)
    min_w = min(min_w, abs(np.sum(w2)-np.sum(w1)))

print(min_w)
# Buggy code:
n = int(input())
w = sorted([ int(x) for x in input().split() ])
ans = sum(w)
l, r = 0, sum(w)
for i in range(n):
    l += w[i]
    r -= w[i]
    ans = min(ans, abs(l-r))

print(ans)


# Fixed code:
n = int(input())
w = [ int(x) for x in input().split() ]
ans = sum(w)
l, r = 0, sum(w)
for i in range(n):
    l += w[i]
    r -= w[i]
    ans = min(ans, abs(l-r))

print(ans)
# Buggy code:
N = int(input())
W = list(map(int,input().split()))
m = sum(W)

for j in range(N-1):
    W1 = W[:j+1]
    W2 = W[j+1:N]
    print(W1, W2)
    s = abs(sum(W1) - sum(W2))
    m = min(m, s)

print(m)


# Fixed code:
N = int(input())
W = list(map(int,input().split()))
m = sum(W)

for j in range(N-1):
    W1 = W[:j+1]
    W2 = W[j+1:N]
    s = abs(sum(W1) - sum(W2))
    m = min(m, s)

print(m)
# Buggy code:
n = int(input())
w = list(map(int,input().split()))
s = 0
list = []
for i in range(n):
  s += w[i]
for i in range(n):
  t = 0
  for j in range(i):
    t += w[j]
  list.append(abs(s - 2t))
print(min(list))  

# Fixed code:
n = int(input())
w = list(map(int,input().split()))
s = 0
list = []
for i in range(n):
  s += w[i]
for i in range(n):
  t = 0
  for j in range(i):
    t += w[j]
  list.append(abs(s - 2*t))
print(min(list))
# Buggy code:
weight_num = int(input())
weights = [int(i) for i in input().split()]
sum_1_list = []
sum_2_list = []
sum_1 = 0
sum_2 = 0

for i in range(weight_num):
    sum_1 += weights[i]
    sum_2 += weights[len(weights) - (1 + i)]
    sum_1_list.append(sum_1)
    sum_2_list.append(sum_2)

ans = max(sum_1_list)

for i in range(weight_num - 1):
    for j in range(weight_num - 1):
        if ans > abs(sum_1_list[i] - sum_2_list[j]):
            ans = abs(sum_1_list[i] - sum_2_list[j])

print(ans)


# Fixed code:
weight_num = int(input())
weights = [int(i) for i in input().split()]
sum_1_list = []
sum_2_list = []
sum_1 = 0
sum_2 = 0

for i in range(weight_num):
    sum_1 += weights[i]
    sum_2 += weights[len(weights) - (i + 1)]
    sum_1_list.append(sum_1)
    sum_2_list.append(sum_2)

ans = max(sum_1_list)

for i in range(weight_num - 1):
    if ans > abs(sum_1_list[i] - sum_2_list[weight_num - (i + 2)]):
        ans = abs(sum_1_list[i] - sum_2_list[weight_num - (i + 2)])

print(ans)
# Buggy code:
n=int(input())
w= list(map(int, input().split()))
s=sum(w)
t=0
ans=abs(s-2*a[0])
for i in range(n-1):
  t+=a[i]
  ans=min(ans,abs(s-2*t))
print(ans)

# Fixed code:
n=int(input())
w= list(map(int, input().split()))
s=sum(w)
t=0
ans=abs(s-2*w[0])
for i in range(n-1):
  t+=w[i]
  ans=min(ans,abs(s-2*t))
print(ans)
# Buggy code:
n=int(input())
w=list(map(int, input().split())) 
sn=sum(w)
abs_list=[abs(sn-sum(w[:i+1])) for i in range(n)]
print(min(abs_list))

# Fixed code:
n=int(input())
w=list(map(int, input().split()))
sn=sum(w)
abs_list=[abs(2*sum(w[:i+1])-sn) for i in range(n)]
print(min(abs_list))
# Buggy code:
def calc(N, W):
    min_sub = 100000
    num = W
    for i in range(1,N):
        S1 = num[:i]
        S2 = num[i:]
        sub = abs(sum(S1)-sum(S2))
        if min_sub > sub:
            min_sub = sub
    print(min_sub)

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

# Fixed code:
def calc(n, w):
    min_sub = 100000
    N = n
    num = w
    for i in range(1,N):
        S1 = num[:i]
        S2 = num[i:]
        sub = abs(sum(S1)-sum(S2))
        if min_sub > sub:
            min_sub = sub
    print(min_sub)
        
N = int(input())
W = [int(i) for i in input().split()]
calc(N, W)
# Buggy code:
n,w=int(input()),list(map(int,input().split()))
a=w[0]
for i in w[1:]:a.append(a[-1]+i)
ans=a[-1]
for i in a:
  if ans>max(i,ans-i):ans=a[-1]-i
print(ans)

# Fixed code:
n,w=int(input()),list(map(int,input().split()))
a=[w[0]]
for i in w[1:]:a.append(a[-1]+i)
ans=a[-1]
for i in a:
  if ans>abs((a[-1]-i)-i):ans=abs((a[-1]-i)-i)
print(ans)
# Buggy code:
N = int(input())
W = list(map(int, input().split()))
l = sum(W)
r = 0
ans = l
for w in W:
    l -= w
    r += w
    ans = min(abs(r - l))

print(ans)

# Fixed code:
N = int(input())
W = list(map(int, input().split()))
l = sum(W)
r = 0
ans = l
for w in W:
    l -= w
    r += w
    ans = min(abs(r - l), ans)

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


# Fixed code:
n = int(input())
a = list(map(int,input().split()))
ans = 10000000
for i in range(n):
    ans = min(ans,abs(sum(a[:i])- sum(a[i:])))
print(ans)
# Buggy code:
import math
n = int(input())
wn = list(map(int, input().split()))


mini = math.inf
for i in range(n-1):
    new_mini = abs(sum(wn[:i]) -sum(wn[i:]))
    if new_mini < mini:
        mini = new_mini
print(mini)

# Fixed code:
import math
 
n = int(input())
wn = list(map(int, input().split()))
 
mini = 10000000000
for i in range(n-1):
    new_mini = abs(sum(wn[:i+1]) -sum(wn[i+1:]))
    if new_mini < mini:
        mini = new_mini
print(mini)
# Buggy code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
S = l()
S.sort()
ans1 = 0
ans2 = sum(S)
sa = 1000000000
i=0

for i in range(N):
    ans1 += S[i]
    ans2 -= S[i]
    sa = min(sa,abs(ans2-ans1))
    i += 1

print(sa)


# Fixed code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
S = l()
sa = 1000000000

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

print(sa)
# Buggy code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
min = 10**9
for i in range(1,n):
    a = abs(sum(s[:i])-sum(s[i:]))
    if a<min:
        min = a
print(min)     

# Fixed code:
n = int(input())
s = list(map(int,input().split()))
min = 10**9
for i in range(1,n):
    a = abs(sum(s[:i])-sum(s[i:]))
    if a<min:
        min = a
print(min)
# Buggy code:
n = int(input())
p = list(map(int,input().split()))
s1,s2 = 0,0
for i in range(1,n):
    for j in range(0,n):
        if j < i:
            s1 += p[j]
        else:
            s2 += p[j]
    ans = abs(s1-s2)
    s1,s2 = 0,0

print(ans)

# Fixed code:
n = int(input())
p = list(map(int,input().split()))
s1,s2 = 0,0
a = []
for i in range(1,n):
    for j in range(0,n):
        if j < i:
            s1 += p[j]
        else:
            s2 += p[j]
    ans = abs(s1-s2)
    a.append(ans)
    s1,s2 = 0,0

print(min(a))
# Buggy code:
n=int(input())
w=list(map(int,input().split()))
s=w.sum()
p=0
bestsub=100000000

for i in range n:
  p=p+w[i]
  sub=abs(s-p)
  if(bestsub>sub):
    bestsub=sub

print(bestsub)

# Fixed code:
n=int(input())
w=list(map(int,input().split()))
s=sum(w)
p=0
bestsub=100000000

for i in range(n):
  p=p+w[i]
  sub=abs(p-(s-p))
  if(bestsub>sub):
    bestsub=sub

print(bestsub)
# Buggy code:
N = int(input())
arr = list(map(int,input().split()))
res = []
for i in range(N-1):
    res.append(abs(sum(arr[:i+1])-arr(W[i+1:])))
print(min(res))

# Fixed code:
N = int(input())
res = []
arr = list(map(int,input().split()))
for i in range(N-1):
    res.append(abs(sum(arr[:i+1])-sum(arr[i+1:])))
print(min(res))
# Buggy code:
n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 9
le = sum(lis)
ri = sum(lis)
for num in lis:
  le += num
  ri -= num
  ans = min(ans,abs(ri-le))
print(ans)

# Fixed code:
n = int(input())
lis = list(map(int,input().split()))
ans = 10 ** 9
le = 0
ri = sum(lis)
ans = sum(lis)
for num in lis:
  le += num
  ri -= num
  ans = min(ans,abs(ri-le))
print(ans)
# Buggy code:
N = int(input())
W = map(int, input().split())

def calc_sum(W, T):
  S1 = sum(W[:T])
  S2 = sum(W[T:])
  return S1, S2

def calc_abs(S1, S2):
  return abs(S1-S2)
  
min_ = 1000
for i in range(len(W)):
  S1, S1 = calc_sum(W, i)
  j = calc_abs(S1, S2)
  if j < min_:
    min_ = j
    
print(min_)

# Fixed code:
N = int(input())
W = list(map(int, input().split()))
 
def calc_sum(W, T):
  S1 = sum(W[:T])
  S2 = sum(W[T:])
  return S1, S2
 
def calc_abs(S1, S2):
  return abs(S1-S2)
  
min_ = 1000
for i in range(len(W)):
  S1, S2 = calc_sum(W, i)
  j = calc_abs(S1, S2)
  if j < min_:
    min_ = j
    
print(min_)
# Buggy code:
N = int(input())
W = [int(w) for w in input().split
ans = 10000000
for t in range(N):
  less_T = W[:t]
  more_T = W[t:]
  S_l = sum(less_T)
  S_m = sum(more_T)
  d = abs(S_l - S_m)
  if ans > d:
     ans = d
print(ans)

# Fixed code:
N = int(input())
W = [int(w) for w in input().split()]
ans = 100000000
for t in range(N):
  less_T = W[:t]
  more_T = W[t:]
  S_l = sum(less_T)
  S_m = sum(more_T)
  d = abs(S_l - S_m)
  if ans > d:
     ans = d
print(ans)
# Buggy code:
N = map(int,input().split())
W = list(map(int,input().split()))

min_list = []
for i in range(N):
    S1 = sum(W[0:i])
    S2 = sum(W) - sum(W[0:i])
    mi = abs(S1-S2)
    min_list.append(mi)
print(min(min_list))


# Fixed code:
N = int(input())
W = list(map(int,input().split()))
 
min_list = []
for i in range(N):
    mi = abs(sum(W[0:i]) - sum(W[i:]))
    min_list.append(mi)
print(min(min_list))
# Buggy code:
N = int(input())
l = list(map(int,input().split()))

min = 0
for T in range(N-1):
    S1 = 0
    S2 = 0
    for i in range(T+1):
        S1 += l[i]
    for i in range(T+1,N):
        S2 += l[i]
    if abs(S1-S2) < min:
        min = abs(S1-S2)

print(min)


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

for T in range(N-1):
    S1 = 0
    S2 = 0
    for i in range(T+1):
        S1 += l[i]
    for i in range(T+1,N):
        S2 += l[i]
    if T == 0:
        min = abs(S1-S2)
    elif abs(S1-S2) < min:
        min = abs(S1-S2)

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

# Fixed code:
N = int(input())
L = list(map(int, input().split()))
A = [abs(sum(L[:i])-sum(L[i:]))for i in range(1,N)]
print(min(A))
# Buggy code:
N=int(input())
W = list(map(int, input().split()))
total = 0
for i in range(N):
    total += W[i]
    

ans = total
sumi = 0
loop = True

while loop:
    sumi += W[i]
    if abs(sumi - (total - sumi)) > ans:
        print(ans)
        loop = False
    else:
        ans = abs(sumi - (total - sumi))

# Fixed code:
N=int(input())
W = list(map(int, input().split()))
total = 0
for i in range(N):
    total += W[i]
    

ans = total
sumi = 0
loop = True
i = 0
while loop:
    sumi += W[i]
    if abs(sumi - (total - sumi)) > ans:
        print(ans)
        loop = False
    else:
      ans = abs(sumi - (total - sumi))
      i += 1
# Buggy code:
n=int(input())
w=list(map(int,input().split()))
wa=[0]*(n+1)
for i in range(n):
	wa[i+1] = wa[i]+w[i]

ans = 1234567890
for i in range(1,n+1):
	ans = min(ans,abs(wa[n+1]-wa[i]))
print(ans)

# Fixed code:
n=int(input())
w=list(map(int,input().split()))
wa=[0]*(n+1)
for i in range(n):
	wa[i+1] = wa[i]+w[i]

ans = 1234567890
for i in range(1,n+1):
	ans = min(ans,abs(wa[n]-2*wa[i]))
print(ans)
# Buggy code:
n = int(input())
w = list(map(int,input().split()))
ans = []
for i in range(1,n):
    ans.append(abs(sum(l[:i])-sum(l[i:])))
print(min(ans))

# Fixed code:
n=int(input())
w=list(map(int,input().split()))
ans=[]
for i in range(n):
    ans.append(abs(sum(w[:i])-sum(w[i:])))
print(min(ans))
# Buggy code:
num = int(input())
tmp = input().split()
tmp = [int(i) for i in tmp]

ans = abs(tmp[0] - sum(tmp[1:]))
for i in range(1,num):
  if abs(sum(tmp[:i]) - sum(tmp[i:])) > ans:
    print(ans)
    break
  else:
    ans = abs(sum(tmp[:i]) - sum(tmp[i:]))

# Fixed code:
num = int(input())
tmp = input().split()
tmp = [int(i) for i in tmp]
flg = 0

ans = abs(tmp[0] - sum(tmp[1:]))
for i in range(1,num):
  if abs(sum(tmp[:i]) - sum(tmp[i:])) > ans:
    print(ans)
    flg = 1
    break
  else:
    ans = abs(sum(tmp[:i]) - sum(tmp[i:]))

if flg == 0: print(ans)
# Buggy code:
n = int(input())
weight = list(map(int,input().split()))
min = 99999
for i in range(n-1):
  sum1 = 0
  sum2 = 0
  for j in range(i+1):
    sum1 += weight[j]
  for k in range(n-i-1):
    sum2 += weight[n-k-1]
  sub = sum1 - sum2
  if(sub < 0):
    sub = 0 - sub
  if(sub < min):
    min = sub
print(sub)
  

# Fixed code:
n = int(input())
weight = list(map(int,input().split()))
min = 99999
for i in range(n-1):
  sum1 = 0
  sum2 = 0
  for j in range(i+1):
    sum1 += weight[j]
  for k in range(n-i-1):
    sum2 += weight[n-k-1]
  sub = sum1 - sum2
  if sub < 0:
    sub = 0 - sub
  if sub < min:
    min = sub
print(min)
# Buggy code:
N=input()
W=list(map(int, input().split()))

sum1,sum2=0,0
ans=0
dif=1000

for i in range(N):
    sum1=sum(W[0:i])
    sum2=sum(W[i:])
    now = abs(sum1-sum2)
    if dif > now:
        dif =now

print(dif)

# Fixed code:
N=int(input())
W=list(map(int, input().split()))
 
sum1,sum2=0,0
ans=0
dif=1000
 
for i in range(N):
    sum1=sum(W[0:i])
    sum2=sum(W[i:])
    now = abs(sum1-sum2)
    if dif > now:
        dif =now
 
print(dif)
# Buggy code:
y = input().split()
y = [ int(x) for x in y]
y = y[1:]
sum_go = []
sum_back = []
for i in range(1, num):
    sum_go.append(sum(y[0:i] ))
    sum_back.append(sum(y[i:] ))
result = []
for i in range(len(sum_go)):
    result.append( abs(sum_go[i] - sum_back[i]) )
print(min(result))

# Fixed code:
y = input()
y = input().split()
y = [ int(x) for x in y]
sum_go = []
sum_back = []
for i in range(1, len(y)):
    sum_go.append(sum(y[0:i] ))
    sum_back.append(sum(y[i:] ))
#print(sum_go)
#print(sum_back)
result = []
for i in range(len(sum_go)):
    result.append( abs(sum_go[i] - sum_back[i]) )
print(min(result))
# Buggy code:
def main():
    N,M=map(int,input().split())

    k_list=[]
    swiches=[]
    for i in range(M):
        inp=list(map(int,input().split()))
        k_list.append(inp[0])
        swiches.append(inp[1:])
    P=list(map(int,input().split()))

    res=0
    for SwichStatus in range(pow(2,N)):
        flag=0
        for i in range(M):
            Link=0
            for swich in swiches[i]:
                Link+=1<<(swich-1)
            OnSwich=SwichStatus&Link
            OnCounter=0
            while OnSwich!=0:
                OnCounter+=OnSwich&1
                OnSwich>>=1
            if OnCounter%2!=P[i]:
                flag=1
                break
        if flag!=1:
            res+=1
    
if __name__=="__main__":
    main()



# Fixed code:
def main():
    N,M=map(int,input().split())

    k_list=[]
    swiches=[]
    for i in range(M):
        inp=list(map(int,input().split()))
        k_list.append(inp[0])
        swiches.append(inp[1:])
    P=list(map(int,input().split()))

    res=0
    for SwichStatus in range(pow(2,N)):
        flag=0
        for i in range(M):
            Link=0
            for swich in swiches[i]:
                Link+=1<<(swich-1)
            OnSwich=SwichStatus&Link
            OnCounter=0
            while OnSwich!=0:
                OnCounter+=OnSwich&1
                OnSwich>>=1
            if OnCounter%2!=P[i]:
                flag=1
                break
        if flag!=1:
            res+=1
    print(res)
if __name__=="__main__":
    main()
# Buggy code:
n, m = map(int, input().split())

ss = []
for i in range(m):
    s = list(map(int, input().split()))[1:]
    te = 0
    for sm in s:
        te += 2**(sm-1)
    ss.append(te)

pp = list(map(int, input().split()))
res = 0
for i in range(2**(n-1)):
    tm = True
    for j in range(len(ss)):
        if (i & ss[j]) % 2 != pp[j]:
            tm = False
            break
    if tm:
        res += 1
print(res)

# Fixed code:
n, m = map(int, input().split())

ss = []
for i in range(m):
    s = list(map(int, input().split()))[1:]
    te = 0
    for sm in s:
        te += 2**(sm-1)
    ss.append(te)

pp = list(map(int, input().split()))
res = 0
for i in range(2**n):
    tm = True
    for j in range(len(ss)):
        st = 0
        su = i & ss[j]
        for u in range(n):
            st += (su >> u) & 1
        if st % 2 != pp[j]:
            tm = False
            break
    if tm:
        res += 1
print(res)