Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
X, Y, Z = sorted([X, Y, Z], reverse=True)
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A, B, C = sorted([A, B, C], reverse=True)
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB = sorted(AB, reverse=True)

if len(AB) > K:
    AB = AB[:K + 1]
ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i] + C[j])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Buggy python submission (verdict: Time Limit Exceeded):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB = sorted(AB, reverse=True)

if len(AB) > K:
    AB = AB[:K + 1]
ABC = []
for i in range(len(AB)):
    for j in range(Z):
        ABC.append(AB[i] + C[j])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])

Fixed submission:
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)

ABC = []
for i in range(X):
    if (i + 1) > K:
        break
    for j in range(Y):
        if (i + 1) * (j + 1) > K:
            break
        for l in range(Z):
            if (i + 1) * (j + 1) * (l + 1) > K:
                break
            ABC.append(A[i] + B[j] + C[l])
ABC = sorted(ABC, reverse=True)
print(*ABC[:K])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import re
lines = sys.stdin.readlines()
for line in lines[2:]:
    l, r = map(int, line.split())
    match = re.findall("(AC)", lines[1][l-1:r])
    print(len(match))

Fixed submission:
n, q = map(int, input().split())
S = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if S[i : i+2] == "AC" else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Runtime Error):
import re
lines = sys.stdin.readlines()
for line in lines[2:]:
    l, r = map(int, line.split())
    match = re.findall("(AC)", lines[1][l-1:r])
    print(len(match))

Fixed submission:
n, q = map(int, input().split())
S = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if S[i : i+2] == "AC" else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import re
n, q = map(int, input().split())
S = input()
for i in range(q):
    l, r = map(int, input().split())
    match = re.findall("(AC)", S[l-1:r])
    print(len(match))

Fixed submission:
n, q = map(int, input().split())
S = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if S[i : i+2] == "AC" else 0)

for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
a, b = map(int, input().split())
for i in range(a, b):
    b = b ^ i
print(b)

Fixed submission:
a, b = map(int, input().split())
if b%2 == 1:
    F0_b = (b+1) // 2 % 2
else:
    F0_b = (b) // 2 % 2 ^ b
c = a - 1
if (c)%2 == 1:
    F0_c = (c+1) // 2 % 2
else:
    F0_c = (c) // 2 % 2 ^ c

print(F0_b ^ F0_c)
Buggy python submission (verdict: Runtime Error):
import math
a, b, k =map(int, input().split())
divesor_list = []
if min(a, b) == 1:
    divesor_list = [1]
else:
    for i in range(min(a, b), 0, -1):
            if gcd % i == 0:
                divesor_list.append(i)
print(divesor_list[k-1])

Fixed submission:
import math
a, b, k =map(int, input().split())
divesor_list = []
c = min(a, b)
if c == 1:
    divesor_list = [1]
else:
    for i in range(c, 0, -1):
            if (a % i == 0) & (b % i == 0):
                divesor_list.append(i)
print(divesor_list[k-1])

Buggy python submission (verdict: Runtime Error):
import math
a, b, k =map(int, input().split())
gcd = math.gcd(a,b)
divesor_list = []
if gcd == 1:
    divesor_list = [gcd]
else:
    for i in range(gcd, 0, -1):
        if gcd % i == 0:
            divesor_list.append(i)
print(divesor_list[k-1])

Fixed submission:
import math
a, b, k =map(int, input().split())
divesor_list = []
c = min(a, b)
if c == 1:
    divesor_list = [1]
else:
    for i in range(c, 0, -1):
            if (a % i == 0) & (b % i == 0):
                divesor_list.append(i)
print(divesor_list[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import re
s = sys.stdin.read().strip()
n = len(s)

while len(re.findall("10|01", s)) > 0:
    s = re.sub("10|01", "", s)
print(n - len(s))

Fixed submission:
import sys
s = sys.stdin.read().strip()
n = len(s)
print(2 * min(s.count("0"), s.count("1")))

Buggy python submission (verdict: Time Limit Exceeded):
import re
s = input()
n = len(s)
while len(re.findall("10|01", s)) > 0:
    s = re.sub("10|01", "", s)
print(n - len(s))

Fixed submission:
import sys
s = sys.stdin.read().strip()
n = len(s)
print(2 * min(s.count("0"), s.count("1")))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
a, b, q = map(int, input().split())
S = [int(input()) for i in range(a)]
T = [int(input()) for i in range(b)]
for _ in range(q):
    x = int(input())
    i = bisect_left(S, x)
    j = bisect_left(T, x)
    if i == 0:
        s = [S[0]]
    elif i == len(S):
        s = [S[-1]]
    else:
        s =[S[i - 1], S[i]]
    if j == 0:
        t = [T[0]]
    elif j == len(T):
        t = [T[-1]]
    else:
        t =[T[j - 1], T[j]]
    ans = []
    for i in range(len(s)):
        for j in range(len(t)):
            ans.append(abs(x - s[i]) + abs(s[i] - t[j]))
    for j in range(len(t)):
        for i in range(len(s)):
            ans.append(abs(x - t[j]) + abs(t[j] - s[i]))
    print(min(ans))

Fixed submission:
from bisect import bisect_left
a, b, q = map(int, input().split())
INF = 10 ** 12
S = [int(input()) for i in range(a)]
S.append(INF)
T = [int(input()) for i in range(b)]
T.append(INF)
for _ in range(q):
    x = int(input())
    i = bisect_left(S, x)
    j = bisect_left(T, x)
    ans = []
    for y in [S[i-1],S[i]]:
        for z in [T[j - 1], T[j]]:
            ans.append(abs(x - y) + abs(y - z))
            ans.append(abs(x - z) + abs(z - y))
    print(min(ans))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
dict = dict(zip([i for i in range(1, 10)], [2,5,5,4,5,6,3,7,6]))
INF = 10 ** (N // 2 + 1)
dp = [-INF for i in range(N + 1)]
for a in A:
    dp[dict[a]] = max(dp[dict[a]] , a)
for i in range(N + 1):
    for j in range(1, 10):
        dp[i] = max(dp[i], dp[i - j] * 10 + dp[j], dp[j] * 10 +dp[i - j])
print(dp[N])

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
dict = dict(zip([i for i in range(1, 10)], [2, 5, 5, 4, 5, 6, 3, 7, 6]))
INF = 10 ** (N // 2 + 1)
dp = [-INF for i in range(N + 21)]
for a in A:
    dp[dict[a]] = max(dp[dict[a]], a)
for i in range(N + 1):
    for j in range(1, 10):
        dp[i] = max(dp[i], dp[i - j] * 10 + dp[j], dp[j] * 10 + dp[i - j])
print(dp[N])
Buggy python submission (verdict: Time Limit Exceeded):
N, k = map(int, input().split())
A = list(map(int, input().split()))
SUM = sum(A)
ans = 0
while ans <= k * N + SUM:
    tem = 0
    for a in A:
        tem += a ^ k
    ans = max(ans, tem)
    k -= 1
print(ans)

Fixed submission:
N, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
x = k
for i in range(len(bin(k)) - 1):
    if x <= k:
        tem = 0
        for a in A:
            tem += a ^ x
        ans = max(ans, tem)
    x = list(format(x, '045b'))
    c = 0
    for a in A:
        c += a >> i & 1
    if N <= 2 * c:
        x[-1 - i] = '0'
    else:
        x[-1 - i] = '1'
    x = int('0b' + ''.join(x), 0)
print(ans)
Buggy python submission (verdict: Runtime Error):
mport numpy as np
N, W = map(int, input().split())
dp = np.zeros(W+1, dtype=np.int64)
for _ in range(N):
    w,v = map(int, input().split())
    np.maximum(dp[w:], dp[:-w] + v , dp[w:])
print(max(dp))

Fixed submission:
import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W+1, dtype=np.int64)
for _ in range(N):
    w,v = map(int, input().split())
    np.maximum(dp[w:], dp[:-w] + v , dp[w:])
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
a = len(list(s))
b = len(list(t))
#dp[i][j] をsをi番目、ｔをj番目までの最長共通長
INF = float('inf')
dp = [[-INF for j in range(b+1)] for i in range(a+1)]
for i in range(a+1):
    dp[i][0] = 0
for j in range(b+1):
    dp[0][j] = 0
for i, x in enumerate(list(s)):
    for j, y in enumerate(list(t)):
        if x == y:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
#復元パート
ans = ''
while a > 0 and b >0:

    if dp[a][b] == dp[a-1][b]:
        a -= 1
    elif dp[a][b] == dp[a][b-1]:
        b -= 1
    else:
        ans = list(s)[a-1] + ans
        a -= 1
        b -= 1
print(ans)

Fixed submission:
s = input()
t = input()
a = len(list(s))
b = len(list(t))
#dp[i][j] をsをi番目、ｔをj番目までの最長共通長
INF = float('inf')
dp = [[-INF for j in range(b+1)] for i in range(a+1)]
for i in range(a+1):
    dp[i][0] = 0
for j in range(b+1):
    dp[0][j] = 0
for i, x in enumerate(list(s)):
    for j, y in enumerate(list(t)):
        if x == y:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
#復元パート
ans = ''
while a > 0 and b >0:

    if dp[a][b] == dp[a-1][b]:
        a -= 1
    elif dp[a][b] == dp[a][b-1]:
        b -= 1
    else:
        ans = list(s)[a-1] + ans
        a -= 1
        b -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = np.zeros((H+2, W+2),dtype=int)
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        else:
            dp[i][j] += dp[i][j+1] + dp[i+1][j]
        dp[i][j] %= MOD

print(dp[1][1])

Fixed submission:
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = [[0 for _ in range(W+2)] for _ in range(H+2)]
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        else:
            dp[i][j] += dp[i][j+1] + dp[i+1][j]
        dp[i][j] %= MOD

print(dp[1][1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = np.zeros((H+2, W+2),dtype=int)
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        dp[i][j] %= MOD
        if field[i-1][j] == '.':
            dp[i-1][j] += dp[i][j]
        if field[i][j-1] == '.':
            dp[i][j-1] += dp[i][j]
print(dp[1][1] % MOD)

Fixed submission:
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = [[0 for _ in range(W+2)] for _ in range(H+2)]
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        else:
            dp[i][j] += dp[i][j+1] + dp[i+1][j]
        dp[i][j] %= MOD

print(dp[1][1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = np.zeros((H+2, W+2),dtype=int)
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        if field[i-1][j] == '.':
            dp[i-1][j] += dp[i][j]
            dp[i-1][j] %= MOD
        if field[i][j-1] == '.':
            dp[i][j-1] += dp[i][j]
            dp[i][j-1] %= MOD
print(dp[1][1])

Fixed submission:
MOD = 10**9 + 7
H, W = map(int, input().split())
field = [['#'] * (W + 2)]
for i in range(H):
    field.append(list('#' + input() + '#'))
field.append(['#'] * (W + 2))

dp = [[0 for _ in range(W+2)] for _ in range(H+2)]
dp[H][W] = 1

for i in range(H,0,-1):
    for j in range(W,0,-1):
        if field[i][j] == '#':
            continue
        else:
            dp[i][j] += dp[i][j+1] + dp[i+1][j]
        dp[i][j] %= MOD

print(dp[1][1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(float, input().split()))
dp = [[0 for j in range(N+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(i+1):
        dp[i+1][j] += dp[i][j] * (1-P[i])
        dp[i+1][j+1] += dp[i][j] * P[i]
print(sum(dp[N][N//2+1:]))

Fixed submission:
import numpy as np
N = int(input())
P = list(map(float, input().split()))
dp = np.zeros((N+1,N+1),dtype=float)
dp[0,0] = 1

for i in range(N):
    dp[i+1] += dp[i] * (1-P[i])
    dp[i+1][1:] += dp[i][:-1] * P[i]
print(sum(dp[N, N//2+1:]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
dp = [0] * (1 << N)
dp[0] = 1
MOD = 10 ** 9 + 7
now = {0}
for _ in range(N):
    mat = [1<<i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in now:
        p = dp[k] % MOD
        for m in mat:
            if k & m: # 1101 & 0100 3番目の人はすでにペアになっているためはじく
                continue
            dp[k | m] += p # 1001 | 0010 = 1101
            nxt.add(k | m)
    now = nxt
print(dp[-1] % MOD) #dp[11...11]が答えになる

Fixed submission:
N = int(input())
dp = [0] * (1 << N)
dp[0] = 1
MOD = 10 ** 9 + 7
now = {0}
for _ in range(N):
    mat = [1<<i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in now:
        p = dp[k] % MOD
        for m in mat:
            if k & m: # 1101 & 0100 3番目の人はすでにペアになっているためはじく
                continue
            dp[k | m] += p # 1001 | 0010 = 1101
            nxt.add(k | m)
    now = nxt
print(dp[-1] % MOD) #dp[11...11]が答えになる

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
dp = [0] * (1 << N)
dp[0] = 1
MOD = 10 ** 9 + 7
now = {0}
for _ in range(N):
    mat = [1<<i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in now:
        p = dp[k] % MOD
        for m in mat:
            if k & m: # 1101 & 0100 3番目の人はすでにペアになっているためはじく
                continue
            dp[k | m] += p # 1001 | 0010 = 1101
            nxt.add(k | m)
    now = nxt
print(dp[-1] % MOD) #dp[11...11]が答えになる

Fixed submission:
N = int(input())
dp = [0] * (1 << N)
dp[0] = 1
MOD = 10 ** 9 + 7
now = {0}
for _ in range(N):
    mat = [1<<i for i, v in enumerate(input().split()) if v == '1']
    nxt = set()
    for k in now:
        p = dp[k] % MOD
        for m in mat:
            if k & m: # 1101 & 0100 3番目の人はすでにペアになっているためはじく
                continue
            dp[k | m] += p # 1001 | 0010 = 1101
            nxt.add(k | m)
    now = nxt
print(dp[-1] % MOD) #dp[11...11]が答えになる
Buggy python submission (verdict: Runtime Error):
n = int(input())
grid = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    if (grid[i][0] + grid[i][1]) % 2 != (grid[i][0] + grid[i][1]) % 2:
        print(-1)
        exit()
m = 31
D = [2 ** i for i in range(m)]
if (grid[0][0] + grid[0][1]) % 2 == 0:
    d.insert(0, 1)
w = [[] for i in range(n)]
for i, g in enumerate(grid):
    x, y = g
    for d in D[::-1]:
        if abs(x) >= abs(y):
            if x > 0:
                x -= d
                w[i].append('L')
            else:
                x += d
                w[i].append('R')
        else:
            if y > 0:
                y -= d
                w[i].append('D')
            else:
                y += d
                w[i].append('U')

print(m)
print(*D)
for ans in w:
    print(*ans[::-1], sep='')

Fixed submission:
n = int(input())
grid = [list(map(int, input().split())) for i in range(n)]

for i in range(n - 1):
    if (grid[i][0] + grid[i][1]) % 2 != (grid[i + 1][0] + grid[i + 1][1]) % 2:
        print(-1)
        exit()
m = 31
D = [2 ** i for i in range(m)]
if (grid[0][0] + grid[0][1]) % 2 == 0:
    D.insert(0, 1)
    m += 1
w = [[] for i in range(n)]
for i, g in enumerate(grid):
    x, y = g
    for d in D[::-1]:
        if abs(x) >= abs(y):
            if x > 0:
                x -= d
                w[i].append('R')
            else:
                x += d
                w[i].append('L')
        else:
            if y > 0:
                y -= d
                w[i].append('U')
            else:
                y += d
                w[i].append('D')

print(m)
print(*D)
for ans in w:
    print(*ans[::-1], sep='')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
for _ in range(26):
    sigma = set()
    for x, y in zip(s, t):
        if x != y:
            x, y = sorted([x, y])
            sigma.add((x,y))
    sigma = sorted(sigma)
    for c1, c2 in sigma:
        tem = ""
        for c in s:
            if c == c1:
                tem += c2
            elif c == c2:
                tem += c1
            else:
                tem += c
        s = tem
    if s == t:
        print('Yes')
        exit()
print('No')

Fixed submission:
s = input()
t = input()
a_z = 'abcdefghijklmnopqrstuvwxyz'
D1 = dict(zip([c for c in a_z],[-1 for _ in range(len(a_z))]))
D2 = dict(zip([c for c in a_z],[-1 for _ in range(len(a_z))]))
for x, y in zip(s, t):
    if D1[x] == -1:
        D1[x] = y
    else:
        if D1[x] != y:
            print('No')
            exit()
    if D2[y] == -1:
        D2[y] = x
    else:
        if D2[y] != x:
            print('No')
            exit()
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
L = int(input())
n = len(format(L - 1, 'b')) + 1
m = 2 ** (n - 1) + format(L - 1, 'b').count('1') - 1
print(n, m)
for i in range(n - 1):
    print(i + 1, i + 2, 0)
    print(i + 1, i + 2, 2 ** i)
w = 2 ** (n - 1)
b = int(format(L - 1, 'b')[1:], 2)
for j in range(20, -1, -1):
    if b >> j & 1:
        print(j + 1, n, w)
        w += 2 ** j

Fixed submission:
L = int(input())
b = format(L, 'b')
n = len(b)
m = 2 * (n - 1) + b.count('1') - 1
print(n, m)
for i in range(1, n):
    print(i, i + 1, 0)
    print(i, i + 1, 2 ** (i - 1))
w = 2 ** (n - 1)
for j in range(20,-1,-1):
    if (L - w) >> j & 1:
        print(j + 1, n, w)
        w += 2 ** j
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in range(k+1):
    if s[i] == '1':
        continue
    else:
        print(s[i])
        break
else:
    print('1')

Fixed submission:
s = input()
k = int(input())
s = s[:k]
for c in s:
    if c == '1':
        continue
    else:
        print(c)
        break
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

d, g = map(int, input().split())
points_list = []
for i in range(d):
    p, c = map(int, input().split())
    points = []
    for j in range(p):
        point = [j, (i + 1) * 100 * j]
        points.append(point)
    points.append([j + 1, (i + 1) * 100 * (j + 1) + c])
    points_list.append(points)

total = np.array(points_list.pop())
for points in points_list:
    subtotal = np.array([[0,0]])
    for point in points:
        subtotal = np.append(subtotal, total + point, axis = 0)
    total = np.array(subtotal)

print(min(total[total[:,1] >= g][:,0]))

Fixed submission:
d, g = map(int, input().split())
comp_points = []
P = []
for i in range(d):
    p, c = map(int, input().split())
    comp_points.append([p, (i + 1) * 100 * p + c])
    P.append(p)

ans = 10**10
#bitallsearch
for i in range(2 ** d):
    bit = format(i, "b").zfill(d)
    count = 0
    point = 0
    for j, dot in enumerate(bit):
        if dot == "1":
            count += comp_points[j][0]
            point += comp_points[j][1]
    #add shortage form high point not comp_points
    for b in range(d-1, -1, -1):
        flag = False
        if point >= g:
            ans = min(ans, count)
            break
        if bit[b] == "0":
            flag = True
            for p in range(P[b] - 1):
                count += 1
                point += (b+1) * 100
                if point >= g:
                    ans = min(ans, count)
                    break
        if (point < g) & flag:
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = []
for i in range(n):
    l = s[:i]
    r = s[i + 1:]
    ans.append(l.count('W') + r.count('E'))
print(min(ans))

Fixed submission:
n = int(input())
s = input()
ans = 10**9
l = 0
r = 0
L = [0]
R = [0]
for i in range(n - 1):
    l += s[i].count('W')
    r += s[-i - 1].count('E')
    L.append(l)
    R.append(r)
for l, r in zip(L, R[::-1]):
    ans = min(ans, l + r)
print(ans)
Buggy python submission (verdict: Runtime Error):
, b, c, d = map(int, input().split())
print('Yes' if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d else 'No')

Fixed submission:
a, b, c, d = map(int, input().split())
print('Yes' if (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())
N = len(s)
subs = set()
for i in range(1, N):
    l = s[:i]
    r = s[i:]
    while not l == '':
        subs.add(l)
        l = l[1:]
    while not r == '':
        subs.add(r)
        r = r[:-1]
subs.add(s)
subs = sorted(subs)
print(subs[k-1])

Fixed submission:
s = input()
k = int(input())
N = len(s)
subs = set()
for i in range(1, N):
    l = s[:i]
    r = s[i:]
    if len(l) > k:
        l = l[-k:]
    if len(r) > k:
        r = r[:k]
    while not l == '':
        subs.add(l)
        l = l[1:]
    while not r == '':
        subs.add(r)
        r = r[:-1]
subs.add(s)
subs = sorted(subs)
print(subs[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
def median(L):
    #L = sorted(L)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
x_sort = sorted(x)
for i in range(n):
    b = x_sort.copy()
    b.remove(x[i])
    print(median(b))

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
def median(L):
    L = sorted(L)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
x_median = median(x)
l = median(sorted(x)[:-1])
r = median(sorted(x)[1:])
for i in range(n):
    if x[i] > x_median:
        print(l)
    else:
        print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
def median(list):
    L = sorted(list)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
for i in range(n):
    b = x[:i] + x[i+1:]
    print(median(b))

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
def median(L):
    L = sorted(L)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
x_median = median(x)
l = median(sorted(x)[:-1])
r = median(sorted(x)[1:])
for i in range(n):
    if x[i] > x_median:
        print(l)
    else:
        print(r)