Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


import bisect

cum = [0]
for b in B:
    cum.append(cum[-1] + b)

ans = 0
for i in range(n + 1):
    t = sum(A[:i])
    if t <= k:
        bnum = i
    else:
        bnum = 0
    if t <= k:
        idx = bisect.bisect_right(cum, k - t)
        bnum += idx - 1
    ans = max(ans, bnum)
print(ans)


Fixed submission:
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


import bisect

cum_a = [0]
for a in A:
    cum_a.append(cum_a[-1] + a)

cum = [0]
for b in B:
    cum.append(cum[-1] + b)

ans = 0
for i in range(n + 1):
    t = cum_a[i]
    if t <= k:
        bnum = i
    else:
        bnum = 0
    if t <= k:
        idx = bisect.bisect_right(cum, k - t)
        bnum += idx - 1
    ans = max(ans, bnum)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

A.sort()
A.append(-1)

x = A[0]
flag = True
for a in A:
    if a % x != 0:
        flag = False
if flag:
    print(0)
    exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)


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

A.sort()
A.append(-1)

x = A[0]
if x != 1:
    flag = True
    for a in A:
        if a % x != 0:
            flag = False
    if flag:
        print(0)
        exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A[:-1]):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)

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

A.sort()

x = A[0]
flag = True
for a in A:
    if a % x != 0:
        flag = False
if flag:
    print(0)
    exit()

used = [False] * A[-1]
ans = 0
for idx, a in enumerate(A):
    if used[a - 1]:
        continue
    if idx < n and a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)


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

A.sort()
A.append(-1)

x = A[0]
if x != 1:
    flag = True
    for a in A:
        if a % x != 0:
            flag = False
    if flag:
        print(0)
        exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A[:-1]):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
edges = [[] for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.popleft()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)


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 - 1].append(b - 1)
    edges[b - 1].append(a - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.popleft()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
edges = [[] for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.pop()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)


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 - 1].append(b - 1)
    edges[b - 1].append(a - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.popleft()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
edges = [[] for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.pop()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)


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 - 1].append(b - 1)
    edges[b - 1].append(a - 1)

from collections import deque

q = deque()

prev = [-1] * n

q.append(0)
while q:
    v = q.popleft()
    for e in edges[v]:
        if prev[e] != -1:
            continue
        prev[e] = v
        q.append(e)

print("Yes")
for val in prev[1:]:
    print(val + 1)
Buggy python submission (verdict: Time Limit Exceeded):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()

cr = 0
cg = 0
p = p[:x]
q = q[:y]
for i in range(c-1, -1, -1):
    x = p.pop()
    y = q.pop()
    z = min(x, y)
    if x < y:
        q.append(y)
        if r[i] > z:
            p.insert(0, r[i])
        else:
            p.append(x)
    else:
        p.append(x)
        if r[i] > z:
            q.insert(0, r[i])
        else:
            q.append(y)
print(sum(p) + sum(q))
    
        
        



Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()
from collections import deque
cr = 0
cg = 0
p = p[:x]
q = q[:y]
p = deque(p)
q = deque(q)
for i in range(c-1, -1, -1):
    x = p.pop()
    y = q.pop()
    z = min(x, y)
    if x < y:
        q.append(y)
        if r[i] > z:
            p.appendleft(r[i])
        else:
            p.append(x)
    else:
        p.append(x)
        if r[i] > z:
            q.appendleft(r[i])
        else:
            q.append(y)
print(sum(p) + sum(q))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
Q = int(input())
query = [list(map(str, input().split())) for _ in range(Q)]

d = deque(s)

for q in query:
    if q[0] == '1':
        s = s[::-1]
    else:
        d = deque(s)
        if q[1] == '1':
            d.appendleft(q[2])
        else:
            d.append(q[2])
        d_list = list(d)
        s = ''.join(d_list)

print(s)

Fixed submission:
from collections import deque

s = input()
Q = int(input())
query = [list(map(str, input().split())) for _ in range(Q)]

d = deque(s)

cnt = 0
for q in query:
    if q[0] == '1':
        cnt += 1
    else:
        if q[1] == '1':
            if cnt % 2:
                d.append(q[2])
            else:
                d.appendleft(q[2])
        else:
            if cnt % 2:
                d.appendleft(q[2])
            else:
                d.append(q[2])
        
d_list = list(d)
s = ''.join(d_list)
if cnt % 2 == 0:
    print(s)
else:
    print(s[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(n-k+1):
    e = 0
    for j in range(k):
        e += ((1+p[i+j])*p[i+j]/2)/p[i+j]
    ans = max(ans, e)
print(ans)

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

# ans = 0
# for i in range(n-k+1):
#     e = 0
#     for j in range(k):
#         e += ((1+p[i+j])*p[i+j]/2)/p[i+j]
#     ans = max(ans, e)
# print(ans)

cum = [0]
for i in range(n):
    cum.append(cum[-1] + p[i])

mx = (0, 0)
for i in range(n-k+1):
    idx = i+k-1
    mx = max(mx, (cum[i+k]-cum[i], idx))

ans = 0
for i in range(k):
    ans += ((1+p[mx[1]-i])*p[mx[1]-i]/2)/p[mx[1]-i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
pS = [tuple(map(str, input().split())) for _ in range(M)]

ac = 0
wa = 0

x = 1
i = 0
while x <= N:
    if i >= M:
        break
    if pS[i][0] != str(x):
        x += 1
        continue
    if pS[i][1] == 'WA':
        wa += 1
        i += 1
    if pS[i][1] == 'AC':
        ac += 1
        x += 1
        i += 1

print(ac, wa)

Fixed submission:
N, M = map(int, input().split())
pS = [tuple(map(str, input().split())) for _ in range(M)]

AC = [False] * (N+1)
WA = [0] * (N+1)

pena = 0
for p, s in pS:
    p = int(p)
    if AC[p]:
        continue
    if s == 'WA':
        WA[p] += 1
    else:
        AC[p] = True
        pena += WA[p]
ac = sum(AC)
print(ac, pena)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
pS = [tuple(map(str, input().split())) for _ in range(M)]

if M == 0:
    print(0, 0)
    exit()

ac = 0
wa = 0

x = 1
i = 0
while x <= N:
    if pS[i][0] != str(x):
        x += 1
        continue
    if pS[i][1] == 'WA':
        wa += 1
        i += 1
    if pS[i][1] == 'AC':
        ac += 1
        x += 1
        i += 1

print(ac, wa)

Fixed submission:
N, M = map(int, input().split())
pS = [tuple(map(str, input().split())) for _ in range(M)]

AC = [False] * (N+1)
WA = [0] * (N+1)

pena = 0
for p, s in pS:
    p = int(p)
    if AC[p]:
        continue
    if s == 'WA':
        WA[p] += 1
    else:
        AC[p] = True
        pena += WA[p]
ac = sum(AC)
print(ac, pena)
Buggy python submission (verdict: Time Limit Exceeded):
def prepare(N, MOD):
    fac = [None] * (N+2)
    finv = [None] * (N+2)
    inv = [None] * (N+2)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, N+1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
    return fac, finv

def combination(N, K, fac, finv, MOD):
    if N < K:
        return 0
    if N < 0 or K < 0:
        return 0
    else:
        return fac[N] * (finv[K] * finv[N - K] % MOD) % MOD

MOD = 10 ** 9 + 7

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

A.sort()

ans = 0
for i in range(N):
    fac, finv = prepare(i, MOD)
    comb = combination(i, K-1, fac, finv, MOD)
    ans += A[i] * comb

A.sort(reverse=True)
for i in range(N):
    fac, finv = prepare(i, MOD)
    comb = combination(i, K-1, fac, finv, MOD)
    ans -= A[i] * comb

ans %= MOD
print(ans)

Fixed submission:
def prepare(N, MOD):
    fac = [None] * (N+2)
    finv = [None] * (N+2)
    inv = [None] * (N+2)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, N+1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
    return fac, finv

def combination(N, K, fac, finv, MOD):
    if N < K:
        return 0
    if N < 0 or K < 0:
        return 0
    else:
        return fac[N] * (finv[K] * finv[N - K] % MOD) % MOD

MOD = 10 ** 9 + 7

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

A.sort()

fac, finv = prepare(N, MOD)
ans = 0
for i in range(N):
    comb = combination(i, K-1, fac, finv, MOD)
    ans += A[i] * comb

A.sort(reverse=True)
for i in range(N):
    comb = combination(i, K-1, fac, finv, MOD)
    ans -= A[i] * comb

ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

commands = [''] * N
ans = 0
for i, t in enumerate(T):
        if t = 'r':
                command = 'p'
                point = P
        elif t = 's':
                command = 'r':
                point = R
        elif t = 'p':
                command = 's':
                point = S
        if i-K >= 0 and commands[i-K] == command:
                command = ''
                point = 0
        ans += point
        commands[i] = command

print(ans)

Fixed submission:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

commands = [''] * N
ans = 0
for i, t in enumerate(T):
        if t == 'r':
                command = 'p'
                point = P
        elif t == 's':
                command = 'r'
                point = R
        elif t == 'p':
                command = 's'
                point = S
        if i-K >= 0 and commands[i-K] == command:
                command = ''
                point = 0
        ans += point
        commands[i] = command

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, dist, p=-1, d=0):
    dist[v] = d
    for nv in es[v]:
        if nv == p:
            continue
        dfs(nv, dist, v, d+1)

def calc_dist(x):
    dist = [-1] * n
    dfs(x, dist)
    return dist

dist_t = calc_dist(u)
dist_a = calc_dist(v)

mx = 0
for i in range(n):
    if dist_t[i] < dist_a[i]:
        mx = max(mx, dist_a[i])

ans = mx - 1
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, dist, p=-1, d=0):
    dist[v] = d
    for nv in es[v]:
        if nv == p:
            continue
        dfs(nv, dist, v, d+1)

def calc_dist(x):
    dist = [-1] * n
    dfs(x, dist)
    return dist

dist_t = calc_dist(u)
dist_a = calc_dist(v)

mx = 0
for i in range(n):
    if dist_t[i] < dist_a[i]:
        mx = max(mx, dist_a[i])

ans = mx - 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, dist, p=-1, d=0):
    dist[v] = d
    for nv in es[v]:
        if nv == p:
            continue
        dfs(nv, dist, v, d+1)

def calc_dist(x):
    dist = [-1] * n
    dfs(x, dist)
    return dist

dist_t = calc_dist(u)
dist_a = calc_dist(v)

mx = 0
for i in range(n):
    if dist_t[i] < dist_a[i]:
        mx = max(mx, dist_a[i])

ans = mx - 1
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, dist, p=-1, d=0):
    dist[v] = d
    for nv in es[v]:
        if nv == p:
            continue
        dfs(nv, dist, v, d+1)

def calc_dist(x):
    dist = [-1] * n
    dfs(x, dist)
    return dist

dist_t = calc_dist(u)
dist_a = calc_dist(v)

mx = 0
for i in range(n):
    if dist_t[i] < dist_a[i]:
        mx = max(mx, dist_a[i])

ans = mx - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

Asum = sum(A)
ans = float('inf')
for i in range(len(A)-1):
    s = sum(A[:i+1])
    t = Asum - s
    ans = min(ans, abs(s-t))

print(ans)

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

cum = [0]
for a in A:
    cum.append(cum[-1]+a)

ans = float('inf')
for i in range(n-1):
    s = cum[i+1]
    t = cum[-1] - s
    ans = min(ans, abs(s-t))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, t = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]

ab.sort()

dp = [[0] * t for i in range(n+1)]
ans = 0
for i in range(n):
    for j in range(t):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j - ab[i][0] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - ab[i][0]] + ab[i][1])
    now = dp[i][t-1] + ab[i][1]
    ans = max(ans, now)

print(ans)

Fixed submission:
n, t = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]

ab.sort()

dp = [[0] * t for i in range(n+1)]
ans = 0
for i in range(n):
    for j in range(t):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j - ab[i][0] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - ab[i][0]] + ab[i][1])
    now = dp[i][t-1] + ab[i][1]
    ans = max(ans, now)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))

A.sort()
F.sort(reverse=True)

sumA = sum(A)
if  K >= sumA:
    print(0)
    exit()

def isok(x):
    k = 0
    for a, f in zip(A, F):
        if a > x//f:
            k += a - (x//f)
            if k > K:
                return False
    return True

ng = -1
ok = 10**12+1

while ok - ng > 1:
    mid = (ok - ng)//2
    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

A.sort()
F.sort(reverse=True)

sumA = sum(A)
if  K >= sumA:
    print(0)
    exit()

def isok(x):
    k = 0
    for a, f in zip(A, F):
        if a > x//f:
            k += a - (x//f)
            if k > K:
                return False
    return True

ng = -1
ok = 10**12+1

while ok - ng > 1:
    mid = (ok + ng)//2
    if isok(mid):
        ok = mid
    else:
        ng = mid
print(ok)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))
cnt = 0
# print(list(combinations(l, 3)))
for ele in list(combinations(l, 3)):
    if ele[0] < ele[1] + ele[2] and ele[1] < ele[0] + ele[2] and ele[2] < ele[0] + ele[1]:
        cnt += 1

print(cnt)

Fixed submission:
from itertools import combinations
import bisect
n = int(input())
l = list(map(int, input().split()))

l.sort()
cnt = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        x = l[i] - l[j] + 1
        idx = bisect.bisect_left(l, x)
        if j > idx:
           cnt += j - idx
print(cnt)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

if len(set(s)) == 1:
    ans = len(s) * k //2
else:
    if s[0] != s[-1]:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        ans = cnt * k
    else:
        cnt = 0
        for i in range(len(s) - 1):
            if s[i] == s[i+1]:
                cnt += 1
        tmp = cnt * k

        # # s_head == s_tail
        # s_head = s[0]
        # s_tail = s[-1]
        # a, b = 0, 0
        # for val in s:
        #     if val == s_head:
        #         a += 1
        #     else:
        #         break
        # for val in s[::-1]:
        #     if val == s_tail:
        #         b += 1
        #     else:
        #         break
        
        cnt_s = 0
        i = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt_2 += 1
                i += 2
            else:
                i += 1
        
        s_2 = s * 2
        cnt_s_2 = 0
        i = 0
        while i < 2 * len(s) - 1:
            if s[i] == s[i+1]:
                cnt_s_2 += 1
                i += 2
            else:
                i += 1

        diff = cnt_s_2 - cnt_s
        ans = tmp - diff * (k-1)

print(ans)

Fixed submission:
s = input()
k = int(input())

if len(set(s)) == 1:
    ans = len(s) * k //2
else:
    if s[0] != s[-1]:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        ans = cnt * k
    else:
        i = 0
        cnt = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt += 1
                i += 2
            else:
                i += 1
        tmp = cnt * k

        cnt_s = 0
        i = 0
        while i < len(s) - 1:
            if s[i] == s[i+1]:
                cnt_s += 1
                i += 2
            else:
                i += 1
        
        s_2 = s * 2
        cnt_s_2 = 0
        i = 0
        while i < len(s_2) - 1:
            if s_2[i] == s_2[i+1]:
                cnt_s_2 += 1
                i += 2
            else:
                i += 1

        diff = cnt_s_2 - 2 * cnt_s
        ans = tmp + diff * (k-1)



print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N, K, Q = map(int,input().split())
A = []
for i in range(Q):
    A.append(int(input()))

c = collections.Counter(A)
cnt = [0] * N
for i in range(len(c.most_common())):
    cnt[c.most_common()[i][0]-1] = c.most_common()[i][1]

if K > Q:
    for i in range(N):
        print('Yes')
elif K <= Q:
    for i in cnt:
        if i >= Q-K+1:
            print('Yes')
        else:
            print('No')

Fixed submission:
import collections

N, K, Q = map(int,input().split())
A = []
for i in range(Q):
    A.append(int(input()))

c = collections.Counter(A)
cnt = [0] * N
for i in c.most_common():
    cnt[i[0]-1] = i[1]

if K > Q:
    for i in range(N):
        print('Yes')
elif K <= Q:
    for i in cnt:
        if i >= Q-K+1:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

for i in range(M):
    # idx = A.index(max(A))
    # A[idx] //= 2
    idx = A.index(max(A[:i+1]))
    A[idx] //= 2
 
print(sum(A))

Fixed submission:
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))

A_minus = [-int(a) for a in A]
heapq.heapify(A_minus)

for _ in range(M):
    tmp = -heapq.heappop(A_minus)
    tmp //= 2
    heapq.heappush(A_minus, -tmp)
 
print(-sum(A_minus))

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

for i in range(M):
    idx = A.index(max(A))
    A[idx] //= 2
 
print(sum(A))

Fixed submission:
import heapq

N, M = map(int,input().split())
A = list(map(int,input().split()))

A_minus = [-int(a) for a in A]
heapq.heapify(A_minus)

for _ in range(M):
    tmp = -heapq.heappop(A_minus)
    tmp //= 2
    heapq.heappush(A_minus, -tmp)
 
print(-sum(A_minus))
Buggy python submission (verdict: Runtime Error):
N = int(input())
b = list(map(int,input().split()))

a = []
a.append(b[-1])
for i in range(1,N-1):
    a.append(min(b[-i], b[-(i+1)]))
a.append(max(b[0], b[1]))

print(sum(a))

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

a = []
a.append(b[-1])
for i in range(1,N-1):
    a.append(min(b[-i], b[-(i+1)]))
a.append(max(b[0], a[N-2]))

print(sum(a))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()

score = 0
for i in range(N-1):
    if (S[i] == S[i+1]):
        score += 1
    ans = min(score+2*K, N-1)

print(ans)

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

score = 0
for i in range(N-1):
    if (S[i] == S[i+1]):
        score += 1
ans = min(score+2*K, N-1)

print(ans)