Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02597 (python)

Fixed submission:
n = int(input())
c = list(input())
print(len([i for i, j in zip(sorted(c), c) if i != j])//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = list(input())
flag = False
ans = 0
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
for i in range(n//2):
    if c[i] == "R" and c[n-i-1] == "W":
        continue
    else:
        if c[i] == "W" and c[n-i-1] == "R":
            c[i] = "R"
            c[n-i-1] = "W"
            ans += 1
        elif c[i] == "W" and c[n-i-1] == "W":
            for j in range(n-i,i+1,-1):
                if c[j] == "R":
                    c[i] = "R"
                    c[j] = "W"
                    break
            ans += 1
        elif c[i] == "R" and c[n-i-1] == "R":
            for j in range(i+1, n-i-1):
                if c[j] == "W":
                    c[n-i-1] = "W"
                    c[j] = "R"  
                    break
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = list(input())
flag = False
ans = 0
for i in range(n-1):
    if c[i] == "W" and c[i+1] == "R":
        flag = True
        break
if not flag:
    print(0)
    exit()
if c[0] == "W" and c[-1] == "R":
    ans += 1
    c[0], c[-1] = "R", "W"
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "W":
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
elif c[0] == "R" and c[-1] == "R":
    for i, v in enumerate(a):
        if i != 0 and v == "W":
            c[i] = "R"
            c[-1] = "W"
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
else:
    for i, v in enumerate(reversed(a)):
        if i != 0 and v == "R":
            c[n-1-i] = "W"
            c[0] = "R"
    ans += 1
    for i in range(n-1):
        if c[i] == "W" and c[i+1] == "R":
            ans += 1
    print(ans)
Problem p02624 (python)

Fixed submission:
def main():
    n = int(input())
    nums_table = [2] * (n+1)
    ans = 0
    for i in range(1, n+1):
        nums_table[i] = 2
    nums_table[1] = 1
    for i in range(2, n//2+1):
        for j in range(2*i,n+1,i):
            nums_table[j] += 1
    for i in range(1, n+1):
        ans += i * nums_table[i]
    print(ans)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    input = sys.stdin.readline
    n = int(input())
    nums_table = defaultdict(int)
    ans = 0
    for i in range(1, n+1):
        nums_table[i] = 2
    nums_table[1] = 1
    for i in range(2, n//2+1):
        for j in range(2*i,n+1,i):
            nums_table[j] += 1
    for i in range(1, n+1):
        ans += i * nums_table[i]
    print(ans)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def main():
    input = sys.stdin.readline
    n = int(input())
    nums_table = defaultdict(int)
    ans = 0
    for i in range(1, n+1):
        for j in range(i,n+1,i):
            nums_table[j-1] += 1
    for i, v in nums_table.items():
        ans += (i+1)*v
    print(ans)
if __name__ == "__main__":
    main()
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
for i in range(1,4):
  if i != a and i != b:
    print(i)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
s = set([a,b])
s_ = set(range(1,4))
print((s_ - s)[0])
Problem p02831 (python)

Fixed submission:
from fractions import gcd
a, b = map(int, input().split())
print((a*b)//gcd(a,b))

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b = map(int, input().split())
print((a*b)//gcd(a,b))
Problem p02862 (python)

Fixed submission:
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, MOD-2, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    

n = (X+Y)//3
r = X-n
if not 0 <= r <= n:
    print(0)
    exit()

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    comb_init()
    print(comb(num, p))

Buggy submission (verdict: Runtime Error):
# nCk(mod p)の計算
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9+7
MAX = 10**6+1

 # a!のテーブルfact
fact = [0] * MAX
# (a!)^-1のテーブルfinv
finv = [0] * MAX

def comb_init():
    # a!と(a!)^-1のテーブルを作る
    # 累積積のイメージ
    fact[0] = fact[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fact[i] = i * fact[i-1] % MOD
        finv[i] = pow(i, -1, MOD) * finv[i-1] % MOD

def comb(n, r):
    return fact[n] * (finv[n-r] * finv[r] % MOD) % MOD    


if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    if not num >= min(p, q) >= 0:
        print(0)
        exit()
    comb_init()
    print(comb(num, min(p, q)))

Buggy submission (verdict: Runtime Error):
from functools import reduce
X, Y = map(int, input().split())
mod = 10**9+7

def comb(n, r):
    numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
    denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
    return numerator * pow(denominator, mod - 2, mod) % mod

if (X+Y) % 3 != 0:
    print(0)
else:
    num = (X+Y)//3
    p = (Y - X + num) // 2
    q = (X + num - Y) // 2
    print(comb(num, p))
Problem p02954 (python)

Fixed submission:
S = input()
seq = [1]
pos = []
for i,(a,b) in enumerate(zip(S,S[1:])):
    if a+b == 'RL':
        pos.append(i)
    if a==b:
        seq[-1] += 1
    else:
        seq.append(1)

ans = [0] * len(S)
for r,l,p in zip(seq[::2],seq[1::2],pos):
    ans[p] = ans[p+1] = (r+l)//2
    if (r+l)%2:
        if r > l:
            ans[p] += 1
        else:
            ans[p+1] += 1
        if max(r,l)%2==0:
            ans[p],ans[p+1] = ans[p+1],ans[p]
print(*ans)

Buggy submission (verdict: Runtime Error):
s = input()
cand = []
ans = [0] * len(s)

# RLの位置を把握
for i in range(len(s)-1):
    if s[i] == "R" and s[i+1] == "L":
        cand.append(i)
for j in range(len(cand)):
    if j == 0:
        lst_l = s[:cand[j]]
        lst_r = s[cand[j]+2:cand[j+1]]
    elif j == len(cand)-1:
        lst_l = s[cand[j-1]+2:cand[j]]
        lst_r = s[cand[j]+2:]
    else:
        lst_l = s[cand[j-1]+2:cand[j]]
        lst_r = s[cand[j]+2:cand[j+1]] 
    num_R = len([i for i in lst_l if i == "R"])
    num_L = len([i for i in lst_r if i == "L"])
    num = num_R + num_L
    j = cand[j]
    if num % 2 == 0:
        ans[j:j+2] = [num//2+1, num//2+1]
    else:
        if num_R == 0 or num_L == 0:
            if num_R == 0:
                ans[j:j+2] = [num_L-(num_L//2)+1, num_L//2+1]
            else:
                ans[j:j+2] = [num_R//2+1, num_R-(num_R//2)+1]
        else:
            ans[j:j+2] = [num_R+1, num_L+1]
print(*ans)
Problem p02987 (python)

Fixed submission:
from collections import defaultdict
S = input()
t = defaultdict(int)
for i in S:
  t[i] += 1
if len(t.keys()) == 2:
  for i in t.values():
    if i != 2:
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
S = input()
t = defaultdict(int)
for i in s:
  t[i] += 1
if len(t.keys()) == 2:
  for i in t.values():
    if i != 2:
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
S = input()
t = defaultdict(int)
for i in s:
  t[i] += 1
if len(t.keys()) == 2:
  for i in t.values():
    if i != 2:
      print("No")
      break
  else:
    print("Yes")
else:
  print("No")
Problem p02623 (python)

Fixed submission:
#import 
#=input()
#=int(input())
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

la = [0]
lb = [0]
for i in range(n):
    la += [a[i]+la[i]]
for i in range(m):
    lb += [b[i]+lb[i]]
j = m
ans = 0
for i in range(n+1):
    if la[i] > k:
        break
    while lb[j] > k - la[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
#import 
#=input()
#=int(input())
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

la = [a[0]]
lb = [b[0]]
for i in range(1,n):
    la += [a[i]+la[i-1]]
for i in range(1,m):
    lb += [b[i]+lb[i-1]]
j = m - 1
ans = 0
for i in range(n):
    if la[i] > k:
        break
    while lb[j] > k - la[i]:
        j -= 1
    ans = max(ans, i+j+2)
print(ans)
Problem p02725 (python)

Fixed submission:
K,N = map(int,input().split())
A = list(map(int,input().split()))

X = A[1] - A[0]
i = 1
while i < N-1:
    Y = A[i+1] - A[i]
    if X < Y:
        X = Y
    i += 1
Z = A[0] + K - A[N-1]
if X < Z:
    X = Z

print(K - X)

Buggy submission (verdict: Runtime Error):
K,N = map(int,input().split())
A = list(map(int,input().split()

X = A[1] - A[0]
i = 1
while i < N-1:
    Y = A[i+1] - A[i]
    if X < Y:
        X = Y
    i += 1
Z = A[0] + K - A[N-1]
if X < Z:
    X = Z

print(K - X)
Problem p02729 (python)

Fixed submission:
N, M = map(int,input().split())

print(N*(N-1)//2 + M*(M-1)//2)

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

return(N*(N-1)//2 + M*(M-1)//2)
Problem p02753 (python)

Fixed submission:
S = input()
 
if (S == 'AAA') or (S == 'BBB'):
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
if S == AAA or BBB:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()

if S == AAA or BBB:
    print('No')
else:
    print('Yes')
Problem p02759 (python)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(int(N / 2))
else:
    print(int(N // 2 + 1))

Buggy submission (verdict: Runtime Error):
N = input()

if N % 2 == 0:
    print(N / 2)
else:
    print(N // 2 + 1)
Problem p02777 (python)

Fixed submission:
S, T = input().split()
A, B = map(int,input().split())
U = input()
 
if S == U:
    print(A-1 , B)
else:
    print(A , B-1)

Buggy submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int,input().split)
U = input()
 
if U == S:
    print(A-1 , B)
else:
    print(A , B-1)

Buggy submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int, input().split)
U = input()
 
if S == U:
    print(A-1 , B)
else:
    print(A , B-1)

Buggy submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int,input().split)
U = input()
 
if S == U:
    print(A-1 , B)
else:
    print(A , B-1)

Buggy submission (verdict: Runtime Error):
S, T = input().split()
A, B = map(int,input().split)
U = input()

if S == U:
    print(A-1 " " B)
else:
    print(A " " B-1)

Buggy submission (verdict: Runtime Error):
S, T = map(input().split())
A, B = map(int,input().split)
U = input()

if S == U:
    print(A-1 " " B)
else:
    print(A " " B-1)

Buggy submission (verdict: Runtime Error):
S, T, U = map(input().split())
A, B = map(int,input().split)

if S == U:
    print(S-1 " " T)
else:
    print(S " " T-1)
Problem p02793 (python)

Fixed submission:
def gcd(x, y): 
      
    while(y): 
        x, y = y, x % y 
      
    return x 
 
n=int(input())
a=list(map(int,input().split()))
x=1
ans=0
for i in a:
    x=(x*i)//gcd(x,i)
for i in a:
    ans+=(x//i)
ans=ans%(1000000007)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n=int(input())
a=list(map(int,input().split()))
x=1
ans=0
for i in a:
    x=(x*i)//(math.gcd(x,i))
for i in a:
    ans+=(x//i)
ans=ans%(1000000007)
print(ans)
Problem p02547 (python)

Fixed submission:
num = input()
d = []
num = int(num)
for n in range(num):
    t, s = input().split()
    d.append([t,s])
flag = 0
for n in range(num):
    if(n<num-2):
        if(d[n][0]==d[n][1] and d[n+1][0]==d[n+1][1] and d[n+2][0]==d[n+2][1]):
            flag = 1
if flag == 1:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
num = input()
d = []
for n in range(num):
    t, s = input().split()
    d.append([t,s])
flag = 0
for n in range(num):
    if(n<num-2):
        if(d[n][0]==d[n][1] and d[n+1][0]==d[n+1][1] and d[n+2][0]==d[n+2][1]):
            flag = 1
if flag == 1:
    print('Yes')
else:
    print('No')
Problem p02570 (python)

Fixed submission:
d,t,s = map(int,input().split())

if(t*s>=d):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
d,t,s = input().split()

if(t*s>=d):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
d,t,s = input().split()

if(t*s>d):
    print('Yes')
else:
    print('No')
Problem p03015 (python)

Fixed submission:
def main():
    L = input().rstrip()
    MOD = 10**9 + 7
    dp = [[0 for equal in range(2)] for digit in range(len(L) + 1)]
    dp[0][0] = 1
    for digit in range(len(L)):
        x = int(L[digit])
        if x == 1:
            dp[digit+1][1] += dp[digit][0] + dp[digit][1]
            dp[digit+1][0] += dp[digit][0] * 2
            dp[digit+1][1] += dp[digit][1] * 2
        else:
            dp[digit+1][0] += dp[digit][0]
            dp[digit+1][1] += dp[digit][1]
            dp[digit+1][1] += dp[digit][1] * 2
        dp[digit+1][0] %= MOD
        dp[digit+1][1] %= MOD
    print((dp[len(L)][0] + dp[len(L)][1])%MOD)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
MOD_t_MAX = 10*5+3
fac  = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv  = [None] * MOD_t_MAX
def MOD_COM_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MOD_t_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
def MOD_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
def MOD_pow(a, n):
    res = 1
    while n > 0:
        if (n & 1):
            res = res * a % MOD
        a = a * a % MOD
        n = n // 2
    return res

def main():
    L = input().rstrip()
    MOD_COM_init()
    cnt = [0]*2
    for i in range(len(L)):
        if L[i] == '0':
            cnt[0] += 1
        else:
            cnt[1] += 1
    cnt[1] -= 1
    ans = 0
    for i in range(cnt[1]+1):
        buf1 = MOD_COM(cnt[1], i)
        buf2 = MOD_pow(2, cnt[1]-i)
        ans += buf1 * buf2 % MOD
        ans = ans % MOD
    ans = ans * 2
    for i in range(len(L)):
        buf1 = MOD_COM(len(L)-1, i)
        buf2 = MOD_pow(2, len(L)-1-i)
        ans += buf1 * buf2 % MOD
        ans = ans % MOD
    print(ans)

if __name__ == "__main__":
    main()
Problem p02547 (python)

Fixed submission:
import re
n=int(input())

s = ""
for _ in range(n):
    d1,d2 = input().split()
    if d1==d2:
        s+="1"
    else:
        s+="0"
#print(s)
try:
    a = max([len(x) for x in re.findall(r"1+", s)])
    if a >= 3:
        print("Yes")
    else:
        print("No")
except:
    print("No")

Buggy submission (verdict: Runtime Error):
import re
n=int(input())

s = ""
for _ in range(n):
    d1,d2 = input().split()
    if d1==d2:
        s+="1"
    else:
        s+="0"
#print(s)
a = max([len(x) for x in re.findall(r"1+", s)])
if a >= 3:
    print("Yes")
else:
    print("No")
Problem p02571 (python)

Fixed submission:
s=input()
t=input()
s=list(s)
t=list(t)

size = len(t)
ms = []
for i in range(len(s)-size+1):
    # print(s[i:i+size])
    m = sum([a==b for a,b in zip(s[i:i+size], t)])
    ms.append(m)

print(size - max(ms))

Buggy submission (verdict: Runtime Error):
S=list(input())                                                                                                                                        
T=list(input())                                                                                                                                        
                                                                                                                                                       
T_size = len(T)                                                                                                                                        
                                                                                                                                                       
def match_num(x):                                                                                                                                      
    return T_size - sum([1 for a,t in zip(x, T) if a==t])                                                                                              
                                                                                                                                                       
b=[]                                                                                                                                                   
for i in range(len(S)-T_size):                                                                                                                         
    b.append(match_num(S[i:i+T_size]))                                                                                                                 
                                                                                                                                                       
print(min(b))
Problem p02695 (python)

Fixed submission:
N,M,Q=map(int,input().split())

"""
# このアプローチはメモリーエラー
s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)
"""

iidp = [list(map(int,input().split())) for q in range(Q)]
import itertools
al = 0
for s1 in itertools.combinations_with_replacement(list(range(1,M+1)), N):
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)

Buggy submission (verdict: Runtime Error):

N,M,Q=map(int,input().split())


s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n
#for s1 in s:
#    print(s1)
iidp = [list(map(int,input().split())) for q in range(Q)]

al = 0
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al = max(a,al)

print(al)

Buggy submission (verdict: Runtime Error):

N,M,Q=map(int,input().split())


s=[[1]]

#長さNまで
import copy
while True:
    n = []
    for s1 in s:
        for append in range(s1[-1], M+1):
            n1 = copy.copy(s1)
            n1.append(append)
            n.append(n1)
    if len(n[0]) > M:
        break
    s = n

iidp = [list(map(int,input().split())) for q in range(Q)]

al = []
for s1 in s:
    a = 0
    for i1, i2, d, p in iidp:
        if s1[i2-1] - s1[i1-1] == d:
            a += p
    al.append(a)

print(max(al))
Problem p02723 (python)

Fixed submission:
s = input()                                                                                                                
                                                                                                                           
if s[2] == s[3] and s[4] == s[5]:                                                                                          
    print("Yes")                                                                                                           
else:                                                                                                                      
    print("No")

Buggy submission (verdict: Runtime Error):
                                                                                                                           
s = input()                                                                                                                
                                                                                                                           
if s[2] == s[3] and s[4] == s[5]:                                                                                          
    print("Yes")                                                                                                           
else:                                                                                                                      
    print("No")                                                                                                            
abc160_a.py (END)
Problem p02831 (python)

Fixed submission:
import math

def computeGCD(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small+1):
        if((x % i == 0) and (y % i == 0)):
            gcd = i
    return gcd
A, B = map(int, input().split())

print( (A*B)//computeGCD(A, B))

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

print( (A*B)//math.gcd(A, B))
Problem p02832 (python)

Fixed submission:
N=int(input())
xs=map(int,input().split())

cur=1
cnt=0
for x in xs:
    if x == cur:
        cnt += 1
        cur += 1

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

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

cur=1
cnt=0
for x in xs:
    if x == cur:
        cnt += 1
        cur += 1

if cnt == 0:
    print(-1)
else:
Problem p02682 (python)

Fixed submission:
a,b,c,k = map(int, input().split())
t = min(k,a)
k -= min(k,a)
if k:
  k -= b
if k > 0:
  t -= k
print(t)

Buggy submission (verdict: Runtime Error):
a,b,c,k = map(int, input().split())
t = min(k,a)
k -= min(k,a)
if k:
  k -= b
if k > 0:
  t -= min(k)
print(t)
Problem p02880 (python)

Fixed submission:
n = int(input())
for i in range(1, 10):
    if n % i == 0 and (n // i) < 10:
        print('Yes')
        break
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
for  i in range(1, 10):
	if n % i == 0 and (n // i) < 10:
    	print('Yes')
        break
else:
	print('No')
Problem p03012 (python)

Fixed submission:
N = int(input())
W = list(map(int, input().split()))

mn = sum(W)
for i in range(N):
  tmp = abs(sum(W[:i])-sum(W[i:]))
  if mn > tmp:
    mn = tmp
print(mn)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
w = list(map(int, input().split()))
mx = sum(w)
w = Counter(w)
ans = mx
tmp = 0
for k in sorted(w).keys():
  tmp += w[k] * k
  ans = min(ans, abs(mx - tmp * 2))
print(ans)