Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
if K == 1:
    print(0)
    exit()
C = [[] for _ in range(K)]
m = 0
C[0].append(-1)
for i in range(N):
    m = (m + A[i] - 1) % K
    C[m].append(i)

ans = 0
for k in range(K):
    L = len(C[k])
    if L <= 1:
        continue
    l = r = 0
    while r < L:
        r = bisect_left(C[k], C[k][l]+K-1, l)
        if r == L:
            ans += (L-l)*(L-l-1)//2
        else:
            ans += r - l - 1
            if C[k][r] == C[k][l]+K-1:
                ans += 1
            l += 1
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
if K == 1:
    print(0)
    exit()
C = defaultdict(list)
k_list = set()
m = 0
C[0].append(-1)
for i in range(N):
    m = (m + A[i] - 1) % K
    C[m].append(i)
    k_list.add(m)

ans = 0
for k in k_list:
    L = len(C[k])
    if L <= 1:
        continue
    l = r = 0
    while r < L:
        r = bisect_left(C[k], C[k][l]+K-1, l)
        if r == L:
            ans += (L-l)*(L-l-1)//2
        else:
            ans += r - l - 1
            if C[k][r] == C[k][l]+K-1:
                ans += 1
            l += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
C = [[] for _ in range(K)]
m = 0
C[0].append(-1)
for i in range(N):
    m = (m + A[i] - 1) % K
    C[m].append(i)

ans = 0
for k in range(K):
    L = len(C[k])
    if L <= 1:
        continue
    l = r = 0
    while r < L:
        r = bisect_left(C[k], C[k][l]+K-1, l)
        if r == L:
            ans += (L-l)*(L-l-1)//2
        else:
            ans += r - l - 1
            if C[k][r] == C[k][l]+K-1:
                ans += 1
            l += 1
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
A = inpl()
if K == 1:
    print(0)
    exit()
C = defaultdict(list)
k_list = set()
m = 0
C[0].append(-1)
for i in range(N):
    m = (m + A[i] - 1) % K
    C[m].append(i)
    k_list.add(m)

ans = 0
for k in k_list:
    L = len(C[k])
    if L <= 1:
        continue
    l = r = 0
    while r < L:
        r = bisect_left(C[k], C[k][l]+K-1, l)
        if r == L:
            ans += (L-l)*(L-l-1)//2
        else:
            ans += r - l - 1
            if C[k][r] == C[k][l]+K-1:
                ans += 1
            l += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
H, W, K = inpl()
a = [input() for _ in range(H)]
strawberry = [[] for _ in range(H)]
for h in range(H):
    for w in range(W):
        if a[h][w] == '#':
            strawberry[h].append(w)
empty = []
ans = [[0]*W for _ in range(H)]
s = 1
for h in range(H):
    if len(strawberry[h]) == 0:
        empty.append(h)
        continue
    strawberry[h][-1] = W-1
    i = 0
    for w in range(W):
        ans[h][w] = s
        if w == strawberry[h][i]:
            s += 1
            i += 1

j = 0
if empty and empty[0] == 0:
    j = 1
    while empty[j] == j:
        j += 1
    for k in range(j):
        ans[k] = ans[j]
for e in range(j, len(empty)):
    k = empty[e]
    ans[k] = ans[k-1]

for h in range(H):
    print(' '.join(list(map(str, ans[h]))))


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
H, W, K = inpl()
a = [input() for _ in range(H)]
strawberry = [[] for _ in range(H)]
for h in range(H):
    for w in range(W):
        if a[h][w] == '#':
            strawberry[h].append(w)
empty = []
ans = [[0]*W for _ in range(H)]
s = 1
for h in range(H):
    if len(strawberry[h]) == 0:
        empty.append(h)
        continue
    strawberry[h][-1] = W-1
    i = 0
    for w in range(W):
        ans[h][w] = s
        if w == strawberry[h][i]:
            s += 1
            i += 1

j = 0
while len(empty) > j and empty[j] == j:
    j += 1
for k in range(j):
    ans[k] = ans[j]
for e in range(j, len(empty)):
    k = empty[e]
    ans[k] = ans[k-1]

for h in range(H):
    print(' '.join(list(map(str, ans[h]))))
Buggy python submission (verdict: Runtime Error):
N = int(input)
print(N//2)

Fixed submission:
N = int(input())
print((N-1)//2)
Buggy python submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()
character_pos = [set()]
ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    cpos = character_pos[ord(s)-ord('a')]
    for p in cpos:
        new_continue_list[p] = 1
    cpos.add(i)
    for k, v in continue_list.items():
        if s == S[k+1]  and v + 1 <= i - k - 1:
            new_continue_list[k+1] = v+1
        elif v > ans:
            ans = v
    continue_list = new_continue_list

if len(continue_list.values()) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()

character_pos = [ set() for _ in range(26) ]
for i in range(N):
    character_pos[ord(S[i])-ord('a')].add(i)

ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    for p in character_pos[ord(s)-ord('a')]:
        if p < i:
            new_continue_list[p] = 1
    for k, v in continue_list.items():
        if s == S[k+1]  and v + 1 <= i - k - 1:
            new_continue_list[k+1] = v+1
        elif v > ans:
            ans = v
    continue_list = new_continue_list

if len(continue_list.values()) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N, Q = inpl()
neighbor = [[] for i in range(N)]
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    neighbor[a].append(b)
    neighbor[b].append(a)
X = [0] * N
for _ in range(Q):
    p, x = inpl()
    X[p-1] += x
result = [0] * N
def dfs(node, x, parent):
    x += X[node]
    result[node] = x
    for c in neighbor[node]:
        if c == parent:
            continue
        else:
            dfs(c,x,node)

dfs(0, 0, None)
print(' '.join(map(str,result)))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N, Q = inpl()
neighbor = [[] for i in range(N)]
for i in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    neighbor[a].append(b)
    neighbor[b].append(a)
X = [0] * N
for _ in range(Q):
    p, x = inpl()
    X[p-1] += x

result = [0] * N
result[0] = X[0]
visited = [False] * N
dfs_stack = [0]
x = 0
while dfs_stack:
    node = dfs_stack.pop()
    visited[node] = True
    for c in neighbor[node]:
        if visited[c]:
            continue
        else:
            dfs_stack.append(c)
            result[c] = result[node] + X[c]

print(' '.join(map(str,result)))
Buggy python submission (verdict: Runtime Error):
from math import floor, log2
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
S = input()
U = S + S[::-1]
Sp = sorted([ U[i:i+N] for i in range(N+1)])[0]
n = 0
while Sp[n] == Sp[0]:
    n += 1

if K > int(floor(log2(N/n))):
    print(Sp[0]*N)
else:
    m = n * (2**(K-1))
    if m >= N:
        print(Sp[0]*N)
    else:
        print(Sp[0]*m + Sp[n:n+N-m])


Fixed submission:
from math import floor, log
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
S = input()
U = S + S[::-1]
Sp = sorted([ U[i:i+N] for i in range(N+1)])[0]
n = 0
while Sp[n] == Sp[0]:
    n += 1

if K > int(floor(log(N/n)/log(2))) + 1:
    print(Sp[0]*N)
else:
    m = n * (2**(K-1))
    if m >= N:
        print(Sp[0]*N)
    else:
        print(Sp[0]*m + Sp[n:n+N-m])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    if colors == 0:
        return 0
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        if next_colors <= 0:
            return 0
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        if prod == 0:
            return 0
        next_colors -= 1
    return prod

print(dfs(0,K))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    if colors == 0:
        return 0
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        if next_colors <= 0:
            return 0
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        if prod == 0:
            return 0
        next_colors -= 1
    return prod

print(dfs(0,K))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        next_colors -= 1
    return prod

print(dfs(0,K))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    if colors == 0:
        return 0
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        if next_colors <= 0:
            return 0
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        if prod == 0:
            return 0
        next_colors -= 1
    return prod

print(dfs(0,K))
Buggy python submission (verdict: Time Limit Exceeded):
inpl = lambda: list(map(int,input().split()))
MOD = 10**9+7

def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n,k):
    if k < 0 or k > n:
        return 0
    else:
        return factorial_mod[n]*factorial_inv_mod[k]*factorial_inv_mod[n-k] % MOD

N, K = inpl()
inv = [1]*(N+1)
factorial_mod = [1]*(N+1)
factorial_inv_mod = [1]*(N+1)
for n in range(1,N+1):
    inv[n] = inv_mod(n)
    factorial_mod[n] = factorial_mod[n-1]*n
    factorial_inv_mod[n] = factorial_inv_mod[n-1]*inv[n]

for i in range(1,K+1):
    print((comb_mod(K-1,i-1)*comb_mod(N-K+1,i)) % MOD)

Fixed submission:
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
MOD = 10**9+7

def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n,k,p=MOD):
    ans = 1
    k = min(k,n-k)
    for i in range(k):
        ans = ans * (n-i) * inv[i+1] % p
    return ans

N, K = inpl()
inv = [0]*(N+1)
for n in range(1,N+1):
    inv[n] = inv_mod(n)

for i in range(1,min(K+1,N-K+2)):
    print((comb_mod(K-1,i-1)*comb_mod(N-K+1,i)) % MOD)
for i in range(N-K+2,K+1):
    print(0)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
 
N = int(input())
xy = []
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
xy.sort()
 
edges = defaultdict(int)
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        edges[(p,q)] += 1
 
print(N - max(edges.values()))

Fixed submission:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

N = int(input())
xy = []
field = defaultdict(int)
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
    field[(x,y)] = 1
xy.sort()

pq = set()
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        pq.add((p,q))

ans = N
for p, q in pq:
    removed = defaultdict(int)
    cost = 0
    for x, y in xy:
        if removed[(x,y)]:
            continue
        else:
            removed[(x,y)] = 1
            cost += 1
            while True:
                x += p
                y += q
                if field[(x,y)]:
                    removed[(x,y)] = 1
                else:
                    break
    if cost < ans:
        ans = cost

print(ans)
Buggy python submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))

def output(plus,minus):
    print(sum(plus)-sum(minus))
    p = plus[0]
    for z in minus[1:]:
        print(p,z)
        p -= z
    q = minus[0]
    for w in plus[1:]:
        print(q,w)
        q -= w
    print(p,q)

N = int(input())
A = inpl()
plus = list(filter(lambda x: x>0, A))
minus = list(filter(lambda x: x<0, A))
Np = len(plus)
Nm = len(minus)
Nz = N-Np-Nm

if Np == N:
    plus.sort(reverse=True)
    minus = [plus.pop()]
elif Nm == N:
    minus.sort()
    plus = [minus.pop()]
else:
    if Nm == 0:
        minus = [0]*Nz
    else:
        plus.extend([0]*Nz)

output(plus,minus)

Fixed submission:
inpl = lambda: list(map(int,input().split()))

def output(plus,minus):
    print(sum(plus)-sum(minus))
    p = plus[0]
    for z in minus[1:]:
        print(p,z)
        p -= z
    q = minus[0]
    for w in plus[1:]:
        print(q,w)
        q -= w
    print(p,q)

N = int(input())
A = inpl()
plus = list(filter(lambda x: x>0, A))
minus = list(filter(lambda x: x<0, A))
Np = len(plus)
Nm = len(minus)
Nz = N-Np-Nm

if Np == N:
    plus.sort(reverse=True)
    minus = [plus.pop()]
elif Nm == N:
    minus.sort()
    plus = [minus.pop()]
elif Nz == N:
    plus = [0]*(Nz-1)
    minus = [0]
else:
    if Nm == 0:
        minus = [0]*Nz
    else:
        plus.extend([0]*Nz)

output(plus,minus)
Buggy python submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
    BC.append(inpl())
BC.sort(key=lambda x: -x[1])

D = []
for B, C in BC:
    if len(D) >= N:
        break
    d = [int(C)]*B
    D += d
D.sort(reverse=True)

for i in range(N):
    if D[i] > A[i]:
        A[i] = D[i]
    else:
        break
ans = sum(A)
print(ans)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
    BC.append(inpl())
BC.sort(key=lambda x: -x[1])
t = 0
S = 0
for B,C in BC:
    f = t
    t = f + B
    if t > N:
        t = N
    if f >= N:
        break
    if C >= A[t-1]:
        S += (t-f)*C
    else:
        for i in range(f,t):
            if C >= A[i]:
                S += C
            else:
                t = i
                break
        break
if t < N:
    S += sum(A[t:])
print(S)

Buggy python submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
    BC.append(inpl())
BC.sort(key=lambda x: -x[1])

S = 0
j = 0
b = -1
for i in range(N):
  b += 1
  if b >= BC[j][0]
    j += 1
    b = 0
  if j >= M:
    S += A[i]
    break
  if BC[j][1] > A[i]:
    S += BC[j][1]
  else:
    S += A[i]
    break
S += sum(A[i+1:])
print(S)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
A = inpl()
A.sort()
BC = []
for _ in range(M):
    BC.append(inpl())
BC.sort(key=lambda x: -x[1])
t = 0
S = 0
for B,C in BC:
    f = t
    t = f + B
    if t > N:
        t = N
    if f >= N:
        break
    if C >= A[t-1]:
        S += (t-f)*C
    else:
        for i in range(f,t):
            if C >= A[i]:
                S += C
            else:
                t = i
                break
        break
if t < N:
    S += sum(A[t:])
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
inpl = lambda: list(map(int,input().split()))
N, M ,K = inpl()
MOD = 10**9+7
factor = 1
# MN-2 C K-2 = MN-2 C MN-K = MN-2 C L
L = min(K-2,M*N-K)
for i in range(M*N-L-1,M*N-1):
    factor *= i
for i in range(1,L+1):
    factor //= i
factor %= MOD
ans = ((M*(N-1)*(N+1) + N*(M-1)*(M+1))*M*N //6 * factor) % MOD
print(ans)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N, M ,K = inpl()
MOD = 10**9+7

def mod_inv(a, m=MOD):
    def mod_inv_sub(a, m):
        if a == 1:
            return 1, 0
        else:
            d, r = m//a, m % a
            x, y = mod_inv_sub(r, a)
            return y - d*x, x

    x = mod_inv_sub(a,m)[0]
    if x < 0:
        x += (-x//m + 1) * m
    return x

factor = 1
# MN-2 C K-2 = MN-2 C MN-K = MN-2 C L
L = min(K-2,M*N-K)
for i in range(M*N-L-1,M*N-1):
    factor = factor * i % MOD
for i in range(1,L+1):
    factor = factor * mod_inv(i) % MOD
ans = ((M*(N-1)*(N+1) + N*(M-1)*(M+1))*M*N //6 * factor) % MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
inpl = lambda: list(map(int,input().split()))
H, W = inpl()
A = []
new_black = []
Nb = 0
for h in range(H):
    line = input()
    Aline = [0] * W
    for w in range(W):
        if line[w] == '#':
            Aline[w] = 1
            new_black.append((h,w))
            Nb += 1
    A.append(Aline)
Nw = H*W - Nb
t = 0
while Nw > 0:
    t += 1
    prev_black = new_black
    new_black = []
    for h, w in prev_black:
        for nh, nw in [(h+1,w), (h-1,w), (h,w+1), (h,w-1)]:
            if 0<=nh<H and 0<=nw<W and A[nh][nw] == 0:
                Nw -= 1
                A[nh][nw] = 1
                new_black.append((nh,nw))
print(t)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
H, W = inpl()
A = []
new_black = []
Nb = 0
for h in range(H):
    line = input()
    Aline = [0] * W
    for w in range(W):
        if line[w] == '#':
            Aline[w] = 1
            new_black.append((h,w))
            Nb += 1
    A.append(Aline)
Nw = H*W - Nb
t = 0
while Nw > 0:
    t += 1
    prev_black = new_black
    new_black = []
    for h, w in prev_black:
        for nh, nw in [(h+1,w), (h-1,w), (h,w+1), (h,w-1)]:
            if 0<=nh<H and 0<=nw<W and A[nh][nw] == 0:
                Nw -= 1
                A[nh][nw] = 1
                new_black.append((nh,nw))
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
inpl = lambda: list(map(int,input().split()))
H, W = inpl()
A = []
new_black = []
for h in range(H):
    line = list(input())
    A.append(line)
    blacks = np.where(np.array(line) == '#')[0]
    for w in blacks:
        new_black.append((h,w))
Nw = H*W - len(new_black)
t = 0
while Nw > 0:
    t += 1
    prev_black = new_black
    new_black = []
    for h, w in prev_black:
        for nh, nw in [(h+1,w), (h-1,w), (h,w+1), (h,w-1)]:
            if 0<=nh<H and 0<=nw<W and A[nh][nw] == '.':
                Nw -= 1
                A[nh][nw] = '#'
                new_black.append((nh,nw))
print(t)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
H, W = inpl()
A = []
new_black = []
Nb = 0
for h in range(H):
    line = input()
    Aline = [0] * W
    for w in range(W):
        if line[w] == '#':
            Aline[w] = 1
            new_black.append((h,w))
            Nb += 1
    A.append(Aline)
Nw = H*W - Nb
t = 0
while Nw > 0:
    t += 1
    prev_black = new_black
    new_black = []
    for h, w in prev_black:
        for nh, nw in [(h+1,w), (h-1,w), (h,w+1), (h,w-1)]:
            if 0<=nh<H and 0<=nw<W and A[nh][nw] == 0:
                Nw -= 1
                A[nh][nw] = 1
                new_black.append((nh,nw))
print(t)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
K = int(input())

e = S[K-1]
for i in range(N):
  if S[i] != e:
    S[i] = '*'
print(S)

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

Slist = list(S) 
e = Slist[K-1]
for i in range(N):
  if Slist[i] != e:
    Slist[i] = '*'
print("".join(Slist))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import heapq
inpl = lambda: list(map(int,input().split()))

X, Y, Z, K = inpl()
A = [ sorted(inpl(), reverse=True) for _ in range(3) ]
N = [X, Y, Z]

mem = defaultdict(int)
score = sum([A[i][0] for i in range(3)])
mem[(0,0,0)] = 1
candidates = []
heapq._heappush_max(candidates, (score,(0,0,0)))

for i in range(K):
    c = heapq._heappop_max(candidates)
    print(c[0])
    n = list(c[1])
    
    for p in range(3):
        if n[p] < N[p]-1:
            n[p] += 1
            if mem[tuple(n)] == 0:
                mem[tuple(n)] = 1
                score = sum([A[j][n[j]] for j in range(3)])
                heapq._heappush_max(candidates, (score,tuple(n)))
            n[p] -= 1

Fixed submission:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

X, Y, Z, K = inpl()
A = [ sorted(inpl(), key=lambda x: -x) for _ in range(3) ]
N = [X, Y, Z]

mem = defaultdict(int)
ans = sum([A[i][0] for i in range(3)])
mem[(0,0,0)] = 1
cand = [(ans,0,0,0)]

for i in range(K):
    cand.sort()
    c = cand[-1]
    print(c[0])
    n = [c[1],c[2],c[3]]
    cand.pop(-1)
    
    for p in range(3):
        if n[p] < N[p]-1:
            n[p] += 1
            if mem[(n[0],n[1],n[2])] == 0:
                mem[(n[0],n[1],n[2])] = 1
                cand.append((sum([A[j][n[j]] for j in range(3)]),n[0],n[1],n[2]))
            n[p] -= 1
Buggy python submission (verdict: Time Limit Exceeded):
inpl = lambda: list(map(int,input().split()))
N = int(input())
b = inpl()

def solution(chosen=[0]*N, n=0):
    if n == N:
        return []
    c = 0
    for i in range(N):
        if chosen[i] == 0 and b[i] == i + 1 - c:
            chosen[i] = 1
            s = solution(chosen, n+1)
            if s is None:
                chosen[i] = 0
            else:
                s.append(b[i])
                return s
        elif chosen[i] == 1:
            c += 1
    return None

ans = solution()
if ans is None:
    print(-1)
else:
    for i in range(N):
        print(ans[i])

Fixed submission:
import numpy as np
inpl = lambda: list(map(int,input().split()))
N = int(input())
b = np.array(inpl(),dtype=np.int)

d = np.array(range(1,N+1),dtype=np.int) - b
if len(np.where(d < 0)[0]) > 0:
    print(-1)
    exit()

ans = np.empty(N,dtype=np.int)
for i in range(N):
    z = np.where(d == 0)[0]
    if len(z) == 0:
        print(-1)
        exit()
    else:
        k = z[-1]
        d[k] = -1
        for n in range(k+1,N):
            if d[n] > 0:
                d[n] -= 1
        ans[N-1-i] = b[k]

for i in range(N):
    print(ans[i])