Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, k = input().split()
d = list(map(int, input().split()))

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))

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

a = []

for i in range(10):
    if i not in d:
        a.append(i)

n = list(map(int, list(n)))

for i in range(len(n)):
    if n[i] in d:
        ind = i

        done = False
        while not done:
            for j in range(n[ind]+1, 10):
                if j in a:
                    n[ind] = j
                    done = True
                    break

            if not done:
                ind -= 1

                if ind < 0:
                    n.insert(0, a[1] if a[0] == 0 else a[0])
                    ind = 0
                    done = True

        for j in range(ind+1, len(n)):
            n[j] = a[0]

        break

print("".join(list(map(str, n))))
Buggy python submission (verdict: Time Limit Exceeded):
import math


def f(A, m, K):
    p = sum([a // m for a in A])
    if p > K:
        return False
    else:
        return True


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


left = 1
right = 10 ** 9 + 1

while math.ceil(left) != math.ceil(right):
    m = (left + right) / 2

    if f(A, m, K):
        right = m
    else:
        left = m


print(math.ceil(m))


Fixed submission:
import math


def f(A, m, K):
    p = sum([a // m for a in A])
    if p > K:
        return False
    else:
        return True


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


left = 0
right = 10 ** 9 + 1

while int(left) != int(right):
    m = (left + right) / 2

    if f(A, m, K):
        right = m
    else:
        left = m


print(math.ceil(m))

Buggy python submission (verdict: Time Limit Exceeded):
import math


def f(A, m, K):
    p = sum([a // m for a in A])
    if p > K:
        return False
    else:
        return True


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


left = 1
right = 10 ** 9 + 1

while math.ceil(left) != math.ceil(right):
    m = (left + right) / 2

    if f(A, m, K):
        right = m
    else:
        left = m


print(math.ceil(m))


Fixed submission:
import math


def f(A, m, K):
    p = sum([a // m for a in A])
    if p > K:
        return False
    else:
        return True


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


left = 0
right = 10 ** 9 + 1

while int(left) != int(right):
    m = (left + right) / 2

    if f(A, m, K):
        right = m
    else:
        left = m


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

c = 1
for i in range(K):
    c *= A[i]

C = c
for i in range(0, N - K):
    c //= A[i]
    c *= A[K + i]

    if c > C:
        print("Yes")
    else:
        print("No")
    C = c


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

for i in range(N - K):
    if A[K + i] > A[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
from collections import Counter

import sys

readline = sys.stdin.buffer.readline

def solver(int N, list A, int Q, list BC):
    d = Counter(A)

    sub_s = sum(A)

    for b, c in BC:
        sub_s += d[b] * (c - b)
        d[c] += d[b]
        d[b] = 0

        print(sub_s)


def run():
    N = int(readline())
    A = list(map(int, readline().split()))

    Q = int(readline())
    BC = [list(map(int, readline().split())) for _ in range(Q)]

    solver(N, A, Q, BC)

run()


Fixed submission:
from collections import Counter

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

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

d = Counter(A)

sub_s = sum(A)

for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0

    print(sub_s)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

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

d = Counter(A)

for b, c in BC:
    d[c] += d[b]
    d[b] = 0

    li = [k * v for k, v in d.items()]
    print(sum(li))


Fixed submission:
from collections import Counter

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

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

d = Counter(A)

sub_s = sum(A)

for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0

    print(sub_s)
Buggy python submission (verdict: Runtime Error):
import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)


Fixed submission:
import numpy as np

X, N = map(int, input().split())
P = np.array(list(map(int, input().split())))

P = P - X

for i in range(0, X + 1):
    if i not in P or -i not in P:
        if -i not in P:
            ans = X - i
        else:
            ans = X + i
        break

print(ans)
Buggy python submission (verdict: Runtime Error):
T = list(input())

if T[0] == '?':
    if T[1] == 'D':
        T[0] = 'P'
    else:
        T[0] = 'D'

for i in range(1, len(T) - 1):
    if T[i] == '?':
        if T[i - 1] == 'P':
            T[i] = 'D'
        else:
            if T[i + 1] == 'D':
                T[i] = 'P'
            else:
                T[i] = 'D'

if T[-1] == '?':
    T[-1] = 'D'

print(''.join(T))



Fixed submission:
T = list(input())

if len(T) == 1:
    if T[0] == '?':
        T[0] = 'D'
else:

    if T[0] == '?':
        if T[1] == 'D':
            T[0] = 'P'
        else:
            T[0] = 'D'

    for i in range(1, len(T) - 1):
        if T[i] == '?':
            if T[i - 1] == 'P':
                T[i] = 'D'
            else:
                if T[i + 1] == 'D':
                    T[i] = 'P'
                else:
                    T[i] = 'D'

    if T[-1] == '?':
        T[-1] = 'D'

print(''.join(T))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [A[0]]

for _ in range(1, N + 10):
    b = A[B[-1] - 1]
    if b in B:
        B += [b]
        break
    else:
        B += [b]
        continue

if len(B) >= K:
    print(B[K])
else:
    ind = [i for i, x in enumerate(B) if x == b]

    K = K - ind[0]
    mod = K % (ind[1] - ind[0])

    print(B[ind[0] + mod - 1])


Fixed submission:
import sys

readline = sys.stdin.buffer.readline


def solver(N, K, A):
    i = 0
    i_list = [0]
    reached = [False for _ in range(N)]

    while True:
        next_i = A[i]

        if reached[next_i]:
            break

        reached[next_i] = True

        i_list.append(next_i)
        i = next_i

    m = i_list.index(next_i)

    if m >= K:
        return i_list[K] + 1

    le = len(i_list) - m
    K -= m
    ind = K % le

    return i_list[m + ind] + 1


def run():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = [a - 1 for a in A]

    ans = solver(N, K, A)
    print(ans)


run()
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())

for a in range(0, 10**9):
    a *= a
    bb = X + a**5
    B = bb**0.2

    if isinstance(B, float):
        if B.is_integer():
            print(int(B), a)
            break

    a *= -1
    bb = X + a**5
    B = bb**0.2
    if isinstance(B, float):
        if B.is_integer():
            print(int(B), a)
            break


Fixed submission:
def f(B):
    if isinstance(B, float):
        if abs(B - int(B)) < 10**-6:
            return True
        else:
            return False
    return False


X = int(input())

for a in range(0, 10**5):
    bb = X + a**5
    B = bb**0.2
    if f(B):
        print(int(B), a)
        break

    a *= -1
    bb = X + a**5
    B = bb**0.2
    if f(B):
        print(int(B), a)
        break
Buggy python submission (verdict: Runtime Error):
import collections
import copy

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)

for a in A:
    pC = copy.deepcopy(C)

    ans = 0
    for k, v in pC.items():
        if k == a:
            ans += (v - 1) * (v - 2) // 2
        else:
            ans += v * (v - 1) // 2
    print(ans)



Fixed submission:
L = int(input())

ans = L**3 / 27

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

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)

for a in A:
    pC = copy.deepcopy(C)

    ans = 0
    for k, v in pC.items():
        if k == a:
            ans += (v - 1) * (v - 2) // 2
        else:
            ans += v * (v - 1) // 2
    print(ans)



Fixed submission:
import collections

N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)

D = collections.defaultdict(int)

for k, v in C.items():
    D[k] += v * (v - 1) // 2

pans = sum(D.values())

for a in A:
    p = (C[a] - 1) * (C[a] - 2) // 2
    ans = pans - D[a] + p

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

d = 1
c = 1
for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        d += c
        c *= -1
    else:
        if (int(que[1]) ^ d) == 0:
            S.insert(0, que[2])
        else:
            S.append(que[2])

print(''.join(S) if d == 1 else ''.join(S[::-1]))


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

d = 1
c = 1
for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        d += c
        c *= -1
    else:
        if (int(que[1]) ^ d) == 0:
            S.appendleft(que[2])
        else:
            S.append(que[2])

print(''.join(S) if d == 1 else ''.join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

d = 1
c = 1
for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        d += c
        c *= -1
    else:
        if (int(que[1]) ^ d) == 0:
            S.insert(0, que[2])
        else:
            S.append(que[2])

print(''.join(S) if d == 1 else ''.join(S[::-1]))


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

d = 1
c = 1
for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        d += c
        c *= -1
    else:
        if (int(que[1]) ^ d) == 0:
            S.appendleft(que[2])
        else:
            S.append(que[2])

print(''.join(S) if d == 1 else ''.join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        S = S[::-1]
    else:
        if int(que[1]) == 1:
            S.insert(0, que[2])
        else:
            S.append(que[2])

print(''.join(S))


Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

d = 1
c = 1
for i in range(Q):
    que = list(input().split())
    if que[0] == str(1):
        d += c
        c *= -1
    else:
        if (int(que[1]) ^ d) == 0:
            S.appendleft(que[2])
        else:
            S.append(que[2])

print(''.join(S) if d == 1 else ''.join(S)[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    N, K = map(int, readline().split())
    p = np.array(readline().split(), dtype=np.int32)
    v = np.ones(K)
    q = np.convolve(p, v, mode='vaild')

    print((np.max(q) + K) / 2)


main()


Fixed submission:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def moving_average(a, n=3) :
    ret = np.cumsum(a, dtype=float)
    ret[n:] = ret[n:] - ret[:-n]
    return ret[n - 1:]

def main():
    N, K = map(int, readline().split())
    p = np.array(readline().split(), dtype=np.int32)
    q = moving_average(p, K)

    print((np.max(q) + K) / 2)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

import numpy as np

readline = sys.stdin.buffer.readline

N, K = map(int, readline().split())
p = np.array(list(map(int, readline().split())))
q = np.convolve(p, np.ones(K), mode='valid')

print((np.max(q) + K) / 2)


Fixed submission:
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def moving_average(a, n=3) :
    ret = np.cumsum(a, dtype=float)
    ret[n:] = ret[n:] - ret[:-n]
    return ret[n - 1:]

def main():
    N, K = map(int, readline().split())
    p = np.array(readline().split(), dtype=np.int32)
    q = moving_average(p, K)

    print((np.max(q) + K) / 2)


main()
Buggy python submission (verdict: Runtime Error):
import math


def main():
    N = int(input())

    if N % 2 == 0:
        B = N // 2
        n = math.floor(math.log(B) / math.log(5))

        ans = 0
        for i in range(1, n + 1):
            ans += B // (5**i)

    else:
        ans = 0

    print(int(ans))


main()


Fixed submission:
import math


def main():
    N = int(input())

    if N == 0 or N == 1:
        ans = 0

    elif N % 2 == 0:
        B = N // 2
        n = math.floor(math.log(B) / math.log(5))

        ans = 0
        for i in range(1, n + 1):
            ans += B // (5**i)

    else:
        ans = 0

    print(int(ans))


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


def main():
    N = int(input())
    S = list(input())

    d = collections.defaultdict(int)
    for a in range(N):
        for b in range(a + 1, N):
            for c in range(b + 1, N):
                k = (S[a], S[b], S[c])
                d[k] += 1

    print(len(d.keys()))

main()


Fixed submission:
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = readline()
    S = S.decode("UTF-8")
    S = list(S[0:-1])

    cnt = 0
    for i in range(10):
        if str(i) in S:
            ind_i = S.index(str(i))
        else:
            continue
        for j in range(10):
            if str(j) in S[ind_i + 1:]:
                ind_j = S[ind_i + 1:].index(str(j))
                ind_j += ind_i + 1
            else:
                continue
            for k in range(10):
                if str(k) in S[ind_j + 1:]:
                    cnt += 1
                else:
                    continue

    print(cnt)


main()
Buggy python submission (verdict: Runtime Error):
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    H, W, K = map(int, readline().split())
    S = read().split()
    S = list(map(lambda x: x.decode('UTF-8'), S))

    A = np.zeros([H, W], dtype=np.int32)
    h_num = 0
    ih = []
    for h in range(H):
        ii = 0
        for w in range(W):
            if S[h][w] == "#":
                if ii != 0:
                    h_num += 1
                    A[h:, w:] = h_num
                    ih.append(h)
                else:
                    h_num += 1
                    A[h:, :] = h_num
                    ii += 1

    h_num = 0
    if A[0, 0] == 0:
        for h in range(ih[0]+1):
            ii = 0
            for w in range(W):
                if S[h][w] == "#":
                    if ii != 0:
                        h_num += 1
                        A[0:h, w:] = h_num
                    else:
                        h_num += 1
                        A[0:h, :] = h_num
                        ii += 1

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


main()


Fixed submission:
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    H, W, K = map(int, readline().split())
    S = read().split()
    S = list(map(lambda x: x.decode('UTF-8'), S))

    A = np.zeros([H, W], dtype=np.int32)
    h_num = 0
    ih = []
    for h in range(H):
        ii = 0
        for w in range(W):
            if S[h][w] == "#":
                if ii != 0:
                    h_num += 1
                    A[h:, w:] = h_num
                else:
                    h_num += 1
                    A[h:, :] = h_num
                    ii += 1
                    ih.append(h)

    h_num = 0
    if A[0, 0] == 0:
        for h in range(ih[0]+1):
            ii = 0
            for w in range(W):
                if S[h][w] == "#":
                    if ii != 0:
                        h_num += 1
                        A[0:h, w:] = h_num
                    else:
                        h_num += 1
                        A[0:h, :] = h_num
                        ii += 1

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


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

C = []

for i in range(N):
    for j in range(N):
        if i+1 == A[j]:
            C.append(j+1)
            break

print(' '.join(map(str, C)))


Fixed submission:
import numpy as np

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

C = np.argsort(A) + 1

print(' '.join(map(str, C)))

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

C = []

for i in range(N):
    for j in range(N):
        if i+1 == A[j]:
            C.append(j+1)

print(' '.join(map(str, C)))


Fixed submission:
import numpy as np

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

C = np.argsort(A) + 1

print(' '.join(map(str, C)))
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.append(n)
    return divisors


def pri(n):
    if n == 1:
        return 1

    for i in range(2, int(n/2 + 1)):
        if n % i == 0:
            return 0

    else:
        return 1


A, B = map(int, input().split())

C = gcd(A, B)

d = make_divisors(C)
d.append(1)
d = list(set(d))

cnt = 0
for i in d:
    cnt += pri(i)

print(cnt)


Fixed submission:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.append(n)
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)

    return a


A, B = map(int, input().split())

C = gcd(A, B)

d = prime_factorize(C)
d.append(1)

print(len(list(set(d))))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

A = np.array(list(map(int, input().split())))

for i in range(M):
    max_ind = A.argmax()
    A[max_ind] = A[max_ind] // 2

print(sum(A))


Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))

print(-sum(a))

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

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

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

print(sum(A))

Fixed submission:
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))

print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys

from scipy.misc import comb

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += comb(i, 2)

    print(int(round(cnt)))


main()


Fixed submission:
import collections

N = int(input())

s = []
ps = []
for i in range(N):
    ps = sorted(list(input()))
    s.append(''.join(ps))

d = collections.Counter(s)

cnt = 0
for v in d.values():
    if v != 1:
        cnt += int(v * (v-1) / 2)

print(cnt)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
import sys

from scipy.special import comb

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += comb(i, 2)
    print(int(cnt))


main()


Fixed submission:
import collections

N = int(input())

s = []
ps = []
for i in range(N):
    ps = sorted(list(input()))
    s.append(''.join(ps))

d = collections.Counter(s)

cnt = 0
for v in d.values():
    if v != 1:
        cnt += int(v * (v-1) / 2)

print(cnt)