Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S,T = map(str,input().split())

import sys

for i in range(len(S)):
    if S[i:len(S)] + S[:i] == T:
        print("Yes")
        sys.exit()
    
print("No")

Fixed submission:
S = input()
T = input()

import sys

for i in range(len(S)):
    if S[i:len(S)] + S[:i] == T:
        print("Yes")
        sys.exit()
    
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

ans = 0

for i in range(N):
    ans += (lcm(a)-1)%a[i]
    
print(ans)

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

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

ans = 0
pi = 1

for i in range(N):
    pi *= a[i]

for i in range(N):
    ans += (pi-1)%a[i]
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
  
N = int(input())
a = list(map(int,input().split()))

ans = 0

for i in range(N):
    ans += prime_decomposition(a[i]).count(2)
    
print(ans)

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

ans = 0

for i in range(N):
    num = a[i]
    while num % 2 == 0:
        num = num // 2
        ans += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

Wlist = [0] 
Elist = [0]

for i in range(N):
    Wlist.append(S.count('W',0,i+1))
    Elist.append(S.count('E',0,i+1))
    
ans = []

for i in range(1,N+1):
    ans.append((Elist[-1] - Elist[i]) + (Wlist[i-1]))
    
print(min(ans))

Fixed submission:
N = int(input())
S = input()

Wlist = [0]*(N+1) 
Elist = [0]*(N+1) 

for i in range(1,N+1):
    if S[i-1] == 'W':
        Wlist[i] = Wlist[i-1] + 1
    else:
        Wlist[i] = Wlist[i-1]
        
    if S[i-1] == 'E':
        Elist[i] = Elist[i-1] + 1
    else:
        Elist[i] = Elist[i-1]

ans = []

for i in range(1,N+1):
    ans.append((Elist[-1] - Elist[i]) + (Wlist[i-1]))
    
print(min(ans))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

res = 0
rright = 0
sum = 0
for left in range(n):
    while (right < n and sum^a[right] == sum+a[right]):
        sum += a[right]
        right += 1
    res += right - left
    if left == right:
        right += 1
    else:
        sum -= a[left]
print(res)

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

res = 0
right = 0
sum = 0
for left in range(n):
    while (right < n and sum^a[right] == sum+a[right]):
        sum += a[right]
        right += 1
    res += right - left
    if left == right:
        right += 1
    else:
        sum -= a[left]
print(res)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

N = len(s)
word = []
for i in range(N-k+1):
    j = i+1
    for _ in range(k):
        word.append(s[i:j])
        j += 1
word.sort()

from collections import Counter
c = Counter(word)
keys, values = zip(*c.most_common())
ans = []
for i in range(len(keys)):
    ans.append(keys[i])
ans.sort()
print(ans[k-1])


Fixed submission:
s = input()
k = int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
n = len(s)
lis = set()
for i in range(26):
    for j in range(len(s)):
        if s[j] == alpha[i]:
            for l in range(j, j+k+1):
                if l < n:
                    lis.add(s[j:l+1])
lis = list(lis)
lis.sort()
#print(lis)
#print(k)
print(lis[k-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(min_l)

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

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(mid_l)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = list(map(int,input().split()))

for i in range(N):
    popX = X.pop(i)
    Xsort = sorted(X)
    print(Xsort[(N-1)//2])
    X.insert(i,popX)

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

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(mid_l)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == N-1:
    index -= 1
    
print(a[-1],a[index])

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

import bisect
a.sort()

center = a[-1]//2

index = bisect.bisect_left(a,center)

if a[index] != center:
    if index > 0 and center - a[index-1] < a[index] - center:
        index -= 1
        
if index == n-1:
    index -= 1
    
print(a[-1],a[index])
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
D = int(input())

print(min(A,B)+min(C+D))

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())

print(min(A,B)+min(C,D))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S_first.count(march[i])

import itertools

ans=0
for v in itertools.combinations(march_number,3):
    ans += v[0]*v[1]*v[2]
print(ans)

Fixed submission:
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

import itertools
ans = 0
for v in itertools.combinations(march_number,3):
    ans += v[0]*v[1]*v[2]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S_first.count(march[i])

import itertools
ptr = list(itertools.combinations(march_number,3))

ans = 0
seki = 1

for i in range(len(ptr)):
    for j in range(3):
        seki *= ptr[i][j]
    ans += seki
    seki = 1

print(ans)

Fixed submission:
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

import itertools
ans = 0
for v in itertools.combinations(march_number,3):
    ans += v[0]*v[1]*v[2]
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(N):
    march_number[i] = S.count(march[i])

import itertools
ptr = list(itertools.combinations(march_number,3))

ans = 0
seki = 1

for i in range(len(ptr)):
    for j in range(3):
        seki *= ptr[i][j]
    ans += seki
    seki = 1

print(ans)

Fixed submission:
N = int(input())
S = [input() for i in range(N)]

S_first = [S[i][0] for i in range(N)]
march = ['M','A','R','C','H']
march_number = [0]*5

for i in range(5):
    march_number[i] = S_first.count(march[i])

import itertools
ans = 0
for v in itertools.combinations(march_number,3):
    ans += v[0]*v[1]*v[2]
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = int(input())

if a*b % 2 == 0:
    print('Odd')
else:
    print('Even')

Fixed submission:
a,b = map(int,input().split())

if a*b % 2 != 0:
    print('Odd')
else:
    print('Even')
Buggy python submission (verdict: Time Limit Exceeded):
N,Y = list(map(int,input().split()))

for x in range(0,Y//10000+1):
    for y in range(0,(Y-x*10000)//5000+1):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)

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

for x in range(0,N+1):
    for y in range(0,N+1-x):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)

Buggy python submission (verdict: Time Limit Exceeded):
N,Y = list(map(int,input().split()))

for x in range(0,Y//10000+1):
    for y in range(0,Y//5000+1):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)

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

for x in range(0,N+1):
    for y in range(0,N+1-x):
        if (Y-x*10000-y*5000)%1000 == 0 and Y-x*10000-y*5000 >= 0:
            if x+y+(Y-x*10000-y*5000)//1000 == N:
                print(x,y,(Y-x*10000-y*5000)//1000)
                exit()
            
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

sorted_s = sorted(s)
sorted_t = sorted(t,reverse=True)

import sys
N = max(len(sorted_s),len(sorted_t))

for i in range(N):
    if ord(sorted_s[i]) < ord(sorted_t[i]):
        print('Yes')
        sys.exit()
    elif ord(sorted_s[i]) > ord(sorted_t[i]):
        print('No')
        sys.exit()

if len(sorted_s) < len(sorted_t):
    print('Yes')
else:
    print('No')

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

sorted_s = sorted(s)
sorted_t = sorted(t,reverse=True)

import sys
N = min(len(sorted_s),len(sorted_t))

for i in range(N):
    if ord(sorted_s[i]) < ord(sorted_t[i]):
        print('Yes')
        sys.exit()
    elif ord(sorted_s[i]) > ord(sorted_t[i]):
        print('No')
        sys.exit()

if len(sorted_s) < len(sorted_t):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

sorted_s = sorted(s)
sorted_t = sorted(t,reverse=True)

import sys
N = max(len(sorted_s),len(sorted_t))

for i in range(N):
    if ord(sorted_s[i]) < ord(sorted_t[i]):
        print('Yes')
        sys.exit()
    elif ord(sorted_s[i]) > ord(sorted_t[i]):
        print('No')
        sys.exit()

if ord(sorted_s[N-1]) == ord(sorted_t[N-1]):
    if len(sorted_s) < len(sorted_t):
        print('Yes')
    else:
        print('No')

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

sorted_s = sorted(s)
sorted_t = sorted(t,reverse=True)

import sys
N = min(len(sorted_s),len(sorted_t))

for i in range(N):
    if ord(sorted_s[i]) < ord(sorted_t[i]):
        print('Yes')
        sys.exit()
    elif ord(sorted_s[i]) > ord(sorted_t[i]):
        print('No')
        sys.exit()

if len(sorted_s) < len(sorted_t):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
X = list(map(int,input().split()))

answer = 0

for x in X:
  answer += min(abs(x),abs(K-x))
answer *= 2

print(ans)

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

answer = 0

for x in X:
  answer += min(abs(x),abs(K-x))
answer *= 2

print(answer)
Buggy python submission (verdict: Runtime Error):
X,t = map(int,input().split())

if X >= t:
    print(X-t)
elsel:
    print(0)

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

if X >= t:
    print(X-t)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))

ans = 0

for x in range(min(a),max(a)+1):
    tmp = 0
    for i in range(N):
        if a[i]+1 == x or a[i] == x or a[i]-1 == x:
            tmp += 1
    
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))

ans = 0

for x in range(min(a),max(a)+1):
    tmp = 0
    tmp += a.count(x)
    tmp += a.count(x-1)
    tmp += a.count(x+1)
    
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))

ans = 0

for x in range(min(a),max(a)+1):
    tmp = 0
    tmp += a.count(x)
    tmp += a.count(x-1)
    tmp += a.count(x+1)
    
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = list(map(int,input().split()))

ans = 0

for i in range(N):
    if i+1 == p[i]:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
    elif i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)

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

ans = 0

for i in range(N):
    if i+1 == p[i] and i != N-1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
    elif i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)

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

ans = 0

for i in range(N):
    if i+1 == p[i]:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
        
    if i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)

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

ans = 0

for i in range(N):
    if i+1 == p[i] and i != N-1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
    elif i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)

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

ans = 0

for i in range(N):
    if i+1 == p[i]:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
        
print(ans)

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

ans = 0

for i in range(N):
    if i+1 == p[i] and i != N-1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
    elif i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
x,a,n = map(int,input().split())

A = abs(x-a)
B = abs(x-b)

if A < B:
    print('A')
else:
    print('B')

Fixed submission:
x,a,b = map(int,input().split())

A = abs(x-a)
B = abs(x-b)

if A < B:
    print('A')
else:
    print('B')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

from collections import Counter

A.sort(reverse=True)
d = Counter(A)
d = d.most_common()
d.sort(reverse=True)
x = []

for i in range(len(d)):
    if d[i][1] >= 4:
        x.append(d[i][0])
        x.append(d[i][0])
    elif d[i][1] >= 2:
        x.append(d[i][0])
        
print(x[0]*x[1])
        

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

from collections import Counter

A.sort(reverse=True)
d = Counter(A)
d = d.most_common()
d.sort(reverse=True)
x = []

for i in range(len(d)):
    if d[i][1] >= 4:
        x.append(d[i][0])
        x.append(d[i][0])
    elif d[i][1] >= 2:
        x.append(d[i][0])
        
if len(x) < 2:
    print(0)
else:   
    print(x[0]*x[1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))

one_list = []
two_list = []
four_list = []

for i in range(N):
    if a[i]%2 == 0:
        if a[i]%4 == 0:
            four_list.append(a[i])
        else:
            two_list.append(a[i])
    else:
        one_list.append(a[i])
        
if len(two_list) > 0:
    if len(four_list) >= len(one_list):
        print('Yes')
    else:
        print('No')
else:
    if len(four_list)+1 >= len(one_list)
        print('Yes')
    else:
        print('No')

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

one_list = []
two_list = []
four_list = []

for i in range(N):
    if a[i]%2 == 0:
        if a[i]%4 == 0:
            four_list.append(a[i])
        else:
            two_list.append(a[i])
    else:
        one_list.append(a[i])
        
if len(two_list) > 0:
    if len(four_list) >= len(one_list):
        print('Yes')
    else:
        print('No')
else:
    if len(four_list)+1 >= len(one_list):
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(M)]

start = []
goal = []

import sys

for i in range(M):
    if ab[i][0] == 1:
        start.append(ab[i])
    if ab[i][1] == N:
        goal.append(ab[i])
        
for i in range(len(start)):
    for j in range(len(goal)):
        if len(set(start[i]) | set(goal[j])) == 3:
            print('POSSIBLE')
            sys.exit()
            
print('IMPOSSIBLE')

Fixed submission:
N, M = map(int, input().split())
edges = [[] for i in range(N)]
 
for i in range(M):
    a, b = map(int, input().split())
    edges[a].append(b)
    
#スタートは1なのでedges[1]をみる
for i in edges[1]:
    #edges[1]のつながり先にNがあるかどうか
    if N in edges[i]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
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))

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

a_sum = [0]*N
x = 0

for i in range(N):
    x += a[i]
    a_sum[i] = x
    
ans = 10**18+1
sum_a = sum(a)

for i in range(N-1):
    ans = min(ans,abs(sum_a-2*a_sum[i]))
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))

ans = []

if N%2 == 0:
    for i in range(N):
        if i%2 == 0:
            ans.append(a[i])
        else:
            ans.insert(0,a[i])
else:
    for i in range(N):
        if i%2 == 0:
            ans.insert(0,a[i])
        else:
            ans.append(a[i])

for i in range(N):
    print(ans[i],end=" ")

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

from collections import deque

ans = deque()

if N%2 == 0:
    for i in range(N):
        if i%2 == 0:
            ans.append(a[i])
        else:
            ans.appendleft(a[i])
else:
    for i in range(N):
        if i%2 == 0:
            ans.appendleft(a[i])
        else:
            ans.append(a[i])

for i in range(N):
    print(ans[i],end=" ")
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))

color = [0]*9

for rate in a:
    if rate >= 3200:
        color[8] += 1
    else:
        color[rate//400] += 1
    
ans = 0

for i in range(8):
        if color[i] > 0:
            ans += 1
print(max(ans,1),ans + c[8])

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

color = [0]*9

for rate in a:
    if rate >= 3200:
        color[8] += 1
    else:
        color[rate//400] += 1
    
ans = 0

for i in range(8):
        if color[i] > 0:
            ans += 1
print(max(ans,1),ans + color[8])

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

color = [0]*9

for rate in a:
    if rate >= 3200:
        color[8] += 1
    else:
        color[rate//400] += 1
    
ans = 0

for i in range(8):
        if color[i] > 0:
            ans += 1
    print(max(ans,1),ans + c[8])

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

color = [0]*9

for rate in a:
    if rate >= 3200:
        color[8] += 1
    else:
        color[rate//400] += 1
    
ans = 0

for i in range(8):
        if color[i] > 0:
            ans += 1
print(max(ans,1),ans + color[8])
Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())

dp = [[0]*(W+1) for i in range(N+1)]

for i in range(1,N+1):
    for j in range(W+1):
        if w[i-1] <= j:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1])
        else:
            dp[i][j] = dp[i-1][j]
            
print(dp[-1][-1])

Fixed submission:
n, W = map(int, input().split())
w1, w2, w3, w4 = [], [], [], []
w, v = map(int, input().split())
w1.append(v)

# 4パターンしかない
for _ in range(n-1):
    a, b = map(int, input().split())
    if a == w:
        w1.append(b)
    if a == w+1:
        w2.append(b)
    if a == w+2:
        w3.append(b)
    if a == w+3:
        w4.append(b)
        
# 降順にする
for w_ in [w1, w2, w3, w4]:
    w_.sort(reverse= True)
    
ans = 0
for i in range(0, len(w1)+1):
    for j in range(0, len(w2)+1):
        for k in range(0, len(w3)+1):
            # w4を詰める前にチェック
            res = W - (i * w + j * (w+1) + k * (w+2))
            if res < 0:
                continue
            # w4は詰めれるだけ詰める
            tmp = sum(w1[:i])+sum(w2[:j])+sum(w3[:k])+sum(w4[:res//(w+3)])
            ans = max(tmp, ans)
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))

ans = 0

for x in range(M+1):
    if x%2 == 0:
        ans = max(ans,min(N+x//2,(M-x)//2))
    
print(ans)

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

if M-2*N >= 0:
    print(N + (M-2*N)//4)
else:
    print(M//2)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = list(map(int,input().split()))

count = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                count += 1
                
print(count)

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

count = 0

for x in range(K+1):
    for y in range(K+1):
        if S-x-y >= 0 and K >= S-x-y:
            count += 1
            
print(count)