Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict,deque

def main():
    N = int(input())
    dist = [[] for i in range(N)]
    c = [[] for _ in range(N)]
    l = 0
    d = defaultdict(tuple)
    for i in range(N-1):
        a,b = map(int,input().split())
        dist[a-1].append(b-1)
        l = max(l,len(dist[a-1]))
        d[(a-1,b-1)] = i

    q = deque([0])
    ans = [0 for _ in range(N-1)]
    while q:
        now = q.popleft()
        col = 1
        for fol in dist[now]:
            for i in range(col,N+1):
                if i not in c[now]:
                    ans[d[(now,fol)]] = i
                    c[now].append(i)
                    c[fol].append(i)
                    col += 1
                    break
            q.append(fol)
            
    print(max(ans))
    for i in ans:
        print(i)
        
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(input())
    e = []
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        e.append(b)
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)

    col = 0
    for x in edge:
        col = max(col,len(x))
        
    print(col)
    ans = [-1 for _ in range(N)]
    go = [False for _ in range(N)]
    q = deque([0])
    while q:
        now = q.pop()
        go[now] = True
        c = 0
        for fol in edge[now]:
            if go[fol]:
                continue
            if c != ans[now]:
                ans[fol] = c
            else:
                ans[fol] = col-1
            c += 1
            q.append(fol)
    
    for i in range(N-1):
        print(ans[e[i]-1]+1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N,T = map(int,input().split())
    delay = 0
    food = []
    for _ in range(N):
        a,b = map(int,input().split())
        food.append((a,b))
        delay = max(delay,a)
        
    dp = [0 for _ in range(T+delay)]
    food.sort(key = itemgetter(0))
    
    for a,b in food:
        for i in reversed(range(T)):
            dp[i+a] = max(dp[i+a],dp[i]+b)

    print(max(dp[T:]))
    
if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter
import numpy as np

def main():
    N,T = map(int,input().split())
    food = []
    for _ in range(N):
        a,b = map(int,input().split())
        food.append((a,b))
        
    dp = np.zeros(T,dtype=int)
    food.sort(key = itemgetter(0))
    
    ans = 0
    for a,b in food:
        ans = max(ans,dp[-1]+b)
        dp[a:] = np.maximum(dp[a:],dp[:-a]+b)

    print(ans)
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,M,L = map(int,input().split())
    edge = [[float("inf") for _ in range(N)] for _ in range(N)]
    
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
    
    for i in range(N):
        edge[i][i] = 0

    for i in range(N):
        for j in range(N):
            for k in range(N):
                if (edge[j][k] > edge[j][i]+edge[i][k]):
                    edge[j][k] = edge[j][i]+edge[i][k]
    
    ref = [[float("inf") for _ in range(N)] for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if edge[i][j] <= L:
                ref[i][j] = 1
            
    for i in range(N):
        for j in range(N):
            for k in range(N):
                if (ref[j][k] > ref[j][i]+ref[i][k]):
                    ref[j][k] = ref[j][i]+ref[i][k]

    Q = int(input())
    for _ in range(Q):
        a,b = map(int,input().split())
        print(ref[a-1][b-1]-1 if ref[a-1][b-1] != float("inf") else -1)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = [[INF for _ in range(1<<N)] for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i][j],dp[i+1][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j|bit],dp[i][j]+a)
    
    print(dp[-1][-1] if dp[-1][-1] != INF else -1)
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = [INF for _ in range(1<<N)]
    dp[0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            af = bit|j
            dp[af] = min(dp[af],dp[j]+a)
            
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = np.full((M+1,1<<N),INF, dtype=np.int64)
    dp[0][0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            dp[i+1][j] = min(dp[i][j],dp[i+1][j])
            dp[i+1][j|bit] = min(dp[i+1][j|bit],dp[i][j|bit],dp[i][j]+a)
    
    print(dp[-1][-1] if dp[-1][-1] != INF else -1)
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    INF = 10**7
    k = []
    for _ in range(M):
        a,b = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for i in c:
            bit += 2**(i-1)
        k.append((a,bit))
    dp = [INF for _ in range(1<<N)]
    dp[0] = 0
    for i in range(M):
        a,bit = k[i]
        for j in range(1<<N):
            af = bit|j
            dp[af] = min(dp[af],dp[j]+a)
            
    print(dp[-1] if dp[-1] != INF else -1)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    H = list(map(int,input().split()))
    count = 0
    for i in range(N-1):
        if H[i+1] <= H[i]:
            count += 1
            ans = count
        else:
            count = 0
            ans = 0
        ans = max(ans,count)

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

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

    if N == 1:
        print(0)
    else:
        ans_list = []
        count = 0
        for i in range(N-1):
            if H[i+1] <= H[i]:
                count += 1
            else:
                ans_list.append(count)
                count = 0
        ans_list.append(count)
        print(max(ans_list))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N-1)]
Y = [list(map(int,input().split())) for _ in range(Q)]

con = [[] for _ in range(N)]
for i in range(N-1):
    con[X[i][0]-1]+=[X[i][1]-1]
    con[X[i][1]-1]+=[X[i][0]-1]

dif = [0]*N
for i in range(Q):
    dif[Y[i][0]-1] += Y[i][1]

root = [0]
while root:
    cur = root.pop()
    for i in con[cur]:
        dif[i] += dif[cur]
        con[i].remove(cur)
        root.append(i) 

print(*dif)

Fixed submission:
import sys
input=sys.stdin.readline
def main():
    N,Q = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N-1)]
    Y = [list(map(int,input().split())) for _ in range(Q)]

    con = [[] for _ in range(N)]
    for i in range(N-1):
        con[X[i][0]-1]+=[X[i][1]-1]
        con[X[i][1]-1]+=[X[i][0]-1]

    dif = [0]*N
    for i in range(Q):
        dif[Y[i][0]-1] += Y[i][1]

    root = [0]
    while root:
        cur = root.pop()
        for i in con[cur]:
            dif[i] += dif[cur]
            con[i].remove(cur)
            root.append(i) 
    print(*dif)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    paylist = [[] for _ in range(M)]
    for _ in range(N):
        a,b = map(int,input().split())
        if M >= a:
            paylist[a-1].append(b)

    work = []
    payment = 0
    for i in range(M):
        work += paylist[i]
        work.sort()
        if work != []:
            payment += work.pop()

    print(payment)

if __name__ == "__main__":
    main()

Fixed submission:
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    paylist = [[] for _ in range(M)]
    for _ in range(N):
        a,b = map(int,input().split())
        if M >= a:
            heapq.heappush(paylist[a-1],-b)
    work = []
    payment = 0
    for i in range(M):
        for j in paylist[i]:
            heapq.heappush(work,j)
        if work:
            payment += heapq.heappop(work)

    print(-payment)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    paylist = [[] for _ in range(M)]
    for _ in range(N):
        a,b = map(int,input().split())
        if M >= a:
            paylist[a-1].append(b)

    work = []
    payment = 0
    for i in range(M):
        work += paylist[i]
        work.sort()
        if work != []:
            payment += work.pop()

    print(payment)

if __name__ == "__main__":
    main()

Fixed submission:
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    paylist = [[] for _ in range(M)]
    for _ in range(N):
        a,b = map(int,input().split())
        if M >= a:
            heapq.heappush(paylist[a-1],-b)
    work = []
    payment = 0
    for i in range(M):
        for j in paylist[i]:
            heapq.heappush(work,j)
        if work:
            payment += heapq.heappop(work)

    print(-payment)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N)]

    X.sort(key=lambda X:X[0])
    day = 1
    work = []
    payment = 0
    while day <= M:
        for i in range(N):
            if X[i][0] == day:
                work.append(X[i][1])
                work.sort()
        if work != []:
            payment += work.pop()
        day += 1

    print(payment)

if __name__ == "__main__":
    main()

Fixed submission:
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = map(int,input().split())
    paylist = [[] for _ in range(M)]
    for _ in range(N):
        a,b = map(int,input().split())
        if M >= a:
            heapq.heappush(paylist[a-1],-b)
    work = []
    payment = 0
    for i in range(M):
        for j in paylist[i]:
            heapq.heappush(work,j)
        if work:
            payment += heapq.heappop(work)

    print(-payment)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

for i in range(1,N):
	if max(X[:i])-min(X[i:]) > 1:
		print("No")
		exit()
print("Yes")

Fixed submission:
N = int(input())

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

maxlst = []
minlst = []
R = 10**10
L = 0
for i in range(N):
	L = max(X[i],L) 
	maxlst.append(L)
	R = min(X[-i-1],R)
	minlst.append(R)

minlst.reverse()
for i in range(N-1):
	if maxlst[i]-minlst[i+1] > 1:
		print("No")
		exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = np.array(list(map(int,input().split())))
    s = sum(a)
    div = [1]
    for i in range(2,s//2+1):
        if s%i == 0:
            div.append(i)
    
    div.append(sum(a))
    ans = 1
    for use in div:
        rest = -(a%use)
        rest = np.sort(rest)
        ch = -sum(rest)//use
        do = use*ch+sum(rest[:ch])
        if do <= K:
            ans = use
    
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.buffer.readline
import numpy as np

def main():
    N,K = map(int,input().split())
    a = np.array(list(map(int,input().split())))
    s = sum(a)
            
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n//i)

        return divisors
            
    div = make_divisors(s)
    
    div.sort()
    ans = 1
    for use in div:
        rest = -(a%use)
        rest = np.sort(rest)
        ch = -sum(rest)//use
        do = use*ch+sum(rest[:ch])
        if do <= K:
            ans = use
    
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(input()) for _ in range(N)]

for i in range(N):
	ans = max(A[:i] + A[i+1:])
	print(ans)


Fixed submission:
N = int(input())

A = [int(input()) for _ in range(N)]

B = sorted(A)
for i in range(N):
	if A[i] == B[-1]:
		print(B[-2])
	else:
	    print(B[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
import bisect

def main():
    N = int(input())
    INF = 10**10
    col = [INF]
    for _ in range(N):
        num = int(input())
        ind = bisect.bisect_left(col,num)
        if ind == 0:
            col = [num]+col
        else:
            col[ind-1] = num
    
    print(len(col)-1)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
from collections import deque

def main():
    N = int(input())
    use = deque([int(input())])
    for _ in range(N-1):
        num = int(input())
        index = bisect.bisect_left(use,num)
        if index == 0:
            use.appendleft(num)
        else:
            use[index-1] = num
    
    print(len(use))
    
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
import bisect
from collections import deque

def main():
    N = int(input())
    use = deque([10**9+1])
    for _ in range(N):
        num = int(input())
        if min(use) >= num:
            use.appendleft(num)
        else:
            index = bisect.bisect_left(use,num)
            use[index-1] = num
    
    print(len(use)-1)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
import bisect
from collections import deque

def main():
    N = int(input())
    use = deque([int(input())])
    for _ in range(N-1):
        num = int(input())
        index = bisect.bisect_left(use,num)
        if index == 0:
            use.appendleft(num)
        else:
            use[index-1] = num
    
    print(len(use))
    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N,D = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i):
    tmp = 0
    for k in range(D):
      tmp += (X[i][k] - X[j][k]) ** 2
    tmp = tmp ** 0.5
    if tmp % 1 == 0:
      ans += 1
      
print(ans)

Fixed submission:
N,A,B = (int(x) for x in input().split())
if N * A < B:
  print( N * A )
else:
  print( B )

Buggy python submission (verdict: Runtime Error):
N,D = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(N):
  for j in range(i):
    tmp = 0
    for k in range(D):
      tmp += (X[i][k] - X[j][k]) ** 2
    tmp = tmp ** 0.5
    if tmp % 1 == 0:
      ans += 1
      
print(ans)

Fixed submission:
N,A,B = (int(x) for x in input().split())
if N * A < B:
  print( N * A )
else:
  print( B )
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
from collections import deque
from scipy.special import perm

def main():
    N,K = map(int,input().split())
    tree = [[] for _ in range(N)]
    INF = 10**9+7
    for _ in range(N-1):
        a,b = map(int,input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
        
    q = deque()
    go = [True for _ in range(N)]
    go[0] = False
    for i in tree[0]:
        go[i] = False
    ans = K*perm(K-1,len(tree[0]),exact = True)
    for i in tree[0]:
        q.append(i)
        while q:
            now = q.popleft()
            count = 0
            for fol in tree[now]:
                if go[fol]:
                    count += 1
                    q.append(fol)
                    go[fol] = False
            u = perm(K-2,count,exact = True)
            ans *= u
            ans %= INF
    
    print(ans)
    
if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.buffer.readline
import copy
from collections import deque

def main():
    N,K = map(int,input().split())
    edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        
    go = [False for _ in range(N)]
    go[0] = True
    for num in edge[0]:
        go[num] = True
    MOD = 10**9+7
    fac = [0 for _ in range(K+1)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,K+1):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD
        
    def per(x,y):
        num = ((fac[x]*invfac[x-y])%MOD)
        return num

    if K-1 < len(edge[0]):
        print(0)
        exit()
    ans = K*(per(K-1,len(edge[0])))

    q = deque(edge[0])
    while q:
        now = q.popleft()
        use = 0
        for fol in edge[now]:
            if not go[fol]:
                use += 1
                go[fol] = True
                q.append(fol)
        if use > K-2:
            print(0)
            exit()
        num = per(K-2,use)
        ans *= num
        ans %= MOD
        
    print(ans%MOD)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
S = list(input())
 
s = sorted(s)
 
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')

Fixed submission:
S = list(input())
 
S = sorted(S)
 
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
four = input()
 
four = sorted(four)
if four[1] == four[2] and four[3] == four[4] and four[2] != four[3]:
	print ("Yes")
else:
	print("No")

Fixed submission:
S = list(input())
 
S = sorted(S)
 
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
four = input()

four = sorted(four)
if four[1] = four[2] and four[3] = four[4] and four[2] != four[3]:
	print ("Yes")
else:
	print("No")

Fixed submission:
S = list(input())
 
S = sorted(S)
 
if S[0] == S[1] and S[2] == S[3] and S[0] != S[2]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

ans = 0
for i in range(len(X) - 2):
  if (X[i] > X[i+1] > X[i+2]) or (X[i] < X[i+1] < X[i+2])
  	ans += 1

print(ans)

Fixed submission:
n = int(input())

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

ans = 0
for i in range(len(X) - 2):
  if (X[i] > X[i+1] > X[i+2]) or (X[i] < X[i+1] < X[i+2]):
  	ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

lcm = (C*D) // math.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(Bnondiv-Anondiv)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

lcm = (C*D) // fractions.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())

lcm = (C*D) // math.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

lcm = (C*D) // fractions.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,C,D = map(int,input().split())

count = 0
for i in range(A,B+1):
	if i%C == 0:
		count += 1
	if i%D == 0:
		count += 1
	if i%C == 0 and i%D == 0:
		count -= 1

print(B-A+1-count)

Fixed submission:
import fractions
A,B,C,D = map(int,input().split())

lcm = (C*D) // fractions.gcd(C,D)
Bnondiv = B - (B//C + B//D - B//lcm)
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
print(int(Bnondiv-Anondiv))
Buggy python submission (verdict: Runtime Error):
P,Q,R = map(int.input().split())
 
print(min(P+Q,Q+R,R+P))

Fixed submission:
P,Q,R = map(int,input().split())
 
print(min(P+Q,Q+R,R+P))
Buggy python submission (verdict: Runtime Error):
N = int(input())

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

sumw = sum(W)
for i in range(N):
	ans = abs(sum(W[:,i+1])-sum(W[i+1:]))
	if ans < sumw:
		sumw = ans

print(sumw)

Fixed submission:
N = int(input())

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

sumw = sum(W)
for i in range(N):
	ans = abs(sum(W[:i+1])-sum(W[i+1:]))
	if ans < sumw:
		sumw = ans

print(sumw)