Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03212 (python)

Fixed submission:
def resolve():
    from collections import deque
    n = int(input())
    ans = 0
    num = deque([3,5,7])
    while num[0] <= n:
        test = num.popleft()
        num.append(test * 10 + 3)
        num.append(test * 10 + 5)
        num.append(test * 10 + 7)
        if list(set([int(x) for x in list(str(test))])) == [3,5,7]:
            ans += 1
    print(ans)

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i== "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(input())
    if n < 357:
        print(0)
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a*10+3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
    print(ans)
resolve()
Problem p03263 (python)

Fixed submission:

def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
                    a[i][j] -= 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] % 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i+1][w-1] += 1
                a[i][w-1] -= 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i+1, j+1, i+1, j+2])
                    a[i][j+1] += 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] & 2 == 0:
                continue
            else:
                ans.append([i+1, j+1, i+2, j+1])
                a[i][j+1] += 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    h, w  = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = []
    for i in range(h):
        for j in range(w):
            if j != w-1 :
                if a[i][j] % 2 == 0:
                    continue
                else:
                    ans.append([i, j, i, j+1])
                    a[i][j+1] += 1
    for i in range(h):
        if i != h-1:
            if a[i][w-1] & 2 == 0:
                continue
            else:
                ans.append([i, j, i+1, j])
                a[i][j+1] += 1
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
resolve()
Problem p03319 (python)

Fixed submission:
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    lena = len(a)
    if (lena-k) % (k-1) == 0:
        print(((lena-k) // (k-1))+1)
    else :
        print(((lena-k) // (k-1))+2)
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    lena = len(a)
    if (lena-k) % (k-1) == 0:
        print(((lena-k) // (k-1))+1)
    else :
        print(((lena-k) // (k-1))+2)
 resolve()
Problem p03403 (python)

Fixed submission:
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0]+a+[0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])
 
    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    a = [0, *a, 0]
    total = 0
    for i in range(1, len(a)):
        total += abs(a[i]-a[i-1])

    for i in range(1, len(a)-1):
        a1 = a[i-1]
        a2 = a[i]
        a3 = a[i+1]
        if a1 <= a2 <= a3 or a1 >= a2 >= a3:
            print(total)
        else:
            print(total-2*min(abs(a2-a1), abs(a3-a2)))
resolve()
Problem p02664 (python)

Fixed submission:
t = input()

print(t.replace('?', 'D'))

Buggy submission (verdict: Runtime Error):
t = list(input())

if t[0] == '?' and t[1] == 'D':
    t[0] = 'P'
elif t[0] == '?' and t[1] == 'P':
    t[0] = 'D'
elif t[0] == '?' and t[1] == '?':
    t[0] = 'P'

for i in range(len(t)):
    if t[i] == '?' and t[i-1] =='P':
        t[i] = 'D'
    elif t[i] == '?' and t[i-1] =='D':
        t[i] = 'P'



print(''.join(t))

Buggy submission (verdict: Runtime Error):
t = list(input())

for i in range(len(t)):
    if t[i] == '?' and t[i-1] =='P':
        t[i] = 'D'
    elif t[i] == '?' and t[i+1] =='D':
        t[i] = 'P'
    elif t[i] == '?' and t[i+1] =='?':
        t[i] = 'P'
        t[i+1] = 'D'

print(''.join(t))
Problem p02705 (python)

Fixed submission:
print(int(input())*2*3.14)

Buggy submission (verdict: Runtime Error):
R = int.input()
print(R*2*3.14)

Buggy submission (verdict: Runtime Error):
R = input()
print(R*2*3.14)

Buggy submission (verdict: Runtime Error):
R = input()
print(R*2*pi)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a * b % 2 == 0:
    print("Even")
elif:
    print("Odd")
Problem p03485 (python)

Fixed submission:
import math
A, B = map(int, input().split())
print(math.ceil((A+B)/2))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(math.ceil((A+B)/2))
Problem p03680 (python)

Fixed submission:
n = int(input())
a = []

for i in range(n):
    a.append(int(input())-1)

button = 0
cnt = 0
done = [False] * n

while True:
    if done[button] == False:
        done[button] = True
        cnt += 1
        if a[button] == 1:
            break
        button = a[button]
    else:
        cnt = -1
        break

print(cnt)

Buggy submission (verdict: Runtime Error):
for i in range(n):
    a.append(int(input())-1)

button = 0
cnt = 0
done = [False] * n

while True:
    if done[button] == False:
        done[button] = True
        cnt += 1
        if a[button] == 1:
            break
        button = a[button]
    else:
        cnt = -1
        break

print(cnt)
Problem p03712 (python)

Fixed submission:
h, w = map(int, input().split())

sh = '#'

print(sh * (w+2))
[print(sh + input() + sh) for i in range(h)]
print(sh * (w+2))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())

a = []
b = list([['#']*(w+2)]*(h+2)) #[]で囲うことが重要


for i in range(h):
    a.append(list(input())) #splitを入れなければOK

for j in range(h):
    for k in range(w):
    b[j+1][k+1] = a[j][k]

print(b)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())

a = []
b = list([['#']*(w+2)]*(h+2)) #[]で囲うことが重要


for i in range(h):
    a.append(list(input())) #splitを入れなければOK

for j in range(h):
    for k in range(w)
    b[j+1][k+1] = a[j][k]

print(b)
Problem p02536 (python)

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

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)
print(sum(x < 0 for x in uf.parents)-1)

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

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)
print(sum(x < 0 for x in uf.parents)-1)
Problem p02665 (python)

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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))

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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
        else:
            print(-1)
            print(aaa)
            exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
print(sum(d))

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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    print(aaaaaaa)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    if d[i-1]*2 < x:
        print(-1)
        print(aaaaaaa)
        exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
# print(d)
print(sum(d))

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

d = [1] * (N+1)
d[0] -= A[0]
for i in range(N):
    d[i+1] = d[i] * 2 - A[i+1]

if d[-1] < 0:
    print(-1)
    print(aaaaaaa)
    exit()
else:
    d[-1] = A[-1]
for i in range(N, 0, -1):
    x = d[i]
    x += A[i-1]
    if d[i-1] * 2 < x:
        y = x - A[i-1]
        if (y+1) // 2 + A[i-1] <= d[i-1] * 2:
            x = d[i-1] * 2
    if d[i-1]*2 < x:
        print(-1)
        print(aaaaaaa)
        exit()
    d[i-1] = min(x, d[i-1]+A[i-1])
print(d)
print(sum(d))
Problem p02684 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) > k:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) > k-1:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(l[l.index(x):])
if len(l) >= k-1:
    print(l[k])
else:
    print(l[l.index(x):][(k-l.index(x)) % len(l[l.index(x):])])

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

visited = [False] * n
visited[0] = True
l = [1]
while True:
    x = A[l[-1]-1]
    if visited[x-1]:
        break
    l.append(x)
    visited[x-1] = True
# print(x)
print(l[x-1:][(k-l.index(x)) % len(l[x-1:])])

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
n, k = map(int, readline().split())
A = list(map(int, readline().split()))

l = [1]
while True:
    x = A[l[-1]-1]
    if x in l:
        break
    l.append(x)
print(l[x-1:][k % len(l)])
Problem p02687 (python)

Fixed submission:
s = input()
ans = 'ABC' if s == 'ARC' else 'ARC'
print(ans)

Buggy submission (verdict: Runtime Error):
input()
ans = 'ABC' if s == 'ARC' else 'ARC'
print(ans)
Problem p02690 (python)

Fixed submission:
X = int(input())
for a in range(-200, 200):
    for b in range(-200, 200):
        if a**5 - b**5 == X:
            print(a, b)
            exit()

Buggy submission (verdict: Runtime Error):
X = int(input())
for i in range(1, 10**9):
    if pow(i, 5, X-1) == 0:
        a = i

print(a, -1)
Problem p02720 (python)

Fixed submission:
from collections import deque

k = int(input())
q = deque(range(1, 10))
for _ in range(k):
    x = q.popleft()
    r = x % 10
    if r != 0:
        q.append(10*x + (r - 1))
    q.append(10*x+r)
    if r != 9:
        q.append(10*x + (r + 1))
print(x)

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
k = int(input())
lunlun = []


@lru_cache(maxsize=100000000)
def func(i):
    if int(i) > 3234566667 + 10 or len(i) > 6:
        return
    lunlun.append(int(i))
    f = int(i[0])
    b = int(i[-1])
    if f != 0:
        func(f'{f-1}{i}')
    if f != 9:
        func(f'{f+1}{i}')
    func(f'{f}{i}')
    if b != 0:
        func(f'{i}{b-1}')
    if b != 9:
        func(f'{i}{b+1}')
    func(f'i}{b}')


for i in range(10):
    func(str(i))
lunlun = sorted(set(lunlun))
print(len(lunlun))
print(lunlun[k])
Problem p02780 (python)

Fixed submission:
import sys
from itertools import accumulate


def solve():
    N, K = map(int, sys.stdin.readline().split())
    cusum_p = (0,) + tuple(accumulate(map(int, sys.stdin.read().split())))
    return (max(i - j for i, j in zip(cusum_p[K:], cusum_p[:-K])) + K) / 2


if __name__ == "__main__":
    answer = solve()
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate


def solve():
    N, K = map(int, sys.stdin.readline().split())
    cusum_p = list(accumulate(map(int, sys.stdin.read().split()), initial=0))
    return (max(i - j for i, j in zip(cusum_p[K:], cusum_p[:-K])) + K) / 2


if __name__ == "__main__":
    answer = solve()
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate

N, K = map(int, sys.stdin.readline().split())
cusum = tuple(accumulate(map(int, sys.stdin.read().split()), initial=0))

print((max(i - j for i, j in zip(cusum[K:], cusum[:-K]) + K) / 2)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import accumulate
import numpy as np


def solve():
    N, K, *P = map(int, sys.stdin.read().split())
    n = np.convolve(np.array(P), np.ones(K), mode='valid').argmax()
    cusum = tuple(accumulate(range(1000+1)))
    return sum(cusum[i] / i for i in P[n:n+K])


if __name__ == "__main__":
    answer = solve()
    print(answer)
Problem p02791 (python)

Fixed submission:
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
    print(n)

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    P = list(map(int, input().split()))

    n = 0
    x = 10 ** 20
    for i in range(N):
        if x >= P[i]:
            x = P[i]
            n += 1
	print(n)
resolve()
Problem p02795 (python)

Fixed submission:
def resolve():
    H = int(input())
    W = int(input())
    N = int(input())
    m = max(H, W)
    print(N // m if N / m == N//m else N // m + 1)
resolve()

Buggy submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
print(*([S]*K + [S+1]*(N-K)))

Buggy submission (verdict: Runtime Error):
import sys
import math
read = sys.stdin.buffer.read
H, W, N = map(int, read().split('\n'))
m = max(H, W)
print(math.ceil(N / m))

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))
resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    import math
    H, W, N = map(int, sys.stdin.read().split('\n'))
    m = max(H, W)
    print(math.ceil(N / m))

resolve()
Problem p02797 (python)

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

ans = [S] * K + [10 ** 9 if S != 10 ** 9 else 1] * (N - K)
print(*ans)

Buggy submission (verdict: Runtime Error):
N, K, S = map(int, input())
print(*([S]*K + [S+1]*(N-K)))
Problem p02813 (python)

Fixed submission:
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

dict_order = permutations(range(1, N + 1))

for n, i in enumerate(dict_order):
    if P == i:
        a = n
    if Q == i:
        b = n

print(abs(a - b))

Buggy submission (verdict: Runtime Error):
import fractions
def resolve():

    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))

    print(abs(dict_num(P) - dict_num(Q)))


def dict_num(a):
    rank = 0
    for i in range(len(a)-1, 0, -1):
        rank += a[i] - 1 * fractions.factorial(i) 
resolve()
Problem p02845 (python)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    # caps[caps.index(a)] += 1
    for i in range(3):
        if caps[i] == a:
            caps[i] += 1
            break
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    caps[caps.index(a)] += 1
    ans %= mod
print(ans)
Problem p02855 (python)

Fixed submission:
import sys

readline = sys.stdin.readline
h, w, k = map(int, readline().split())
s = [readline().rstrip() for _ in range(h)]
ans = [[0] * w for _ in range(h)]
peace = 1
not_strawberry = []
for i in range(h):
    strawberry = 0
    for j in range(w):
        if s[i][j] == '#':
            if strawberry == 1:
                peace += 1
                strawberry = 1
            else:
                strawberry = 1
        ans[i][j] = str(peace)
    if not strawberry:
        not_strawberry.append(i)
    else:
        for j in not_strawberry:
            ans[j] = ans[i]
        not_strawberry = []
        peace += 1
if not_strawberry:
    i = min(not_strawberry) - 1
    for j in not_strawberry:
        ans[j] = ans[i]

print('\n'.join(' '.join(i) for i in ans))

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline
h, w, k = map(int, readline().split())
s = [readline().rstrip() for _ in range(h)]
ans = [[0] * w for _ in range(h)]
peace = 1
not_strawberry = []
for i in range(h):
    strawberry = 0
    for j in range(w):
        if s[i][j] == '#':
            if strawberry == 1:
                peace += 1
                strawberry = 1
            else:
                strawberry = 1
        ans[i][j] = str(peace)
    if not strawberry:
        not_strawberry.append(i)
    else:
        for j in not_strawberry:
            ans[j] = ans[i]
        peace += 1
i = min(not_strawberry) - 1
for j in not_strawberry:
    ans[j] = ans[i]

print('\n'.join(' '.join(i) for i in ans))
Problem p02937 (python)

Fixed submission:
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] <= now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

S = input()
T = input()

ss = set(list(S))
st = set(list(T))
if not (st <= ss):
    print(-1)
    exit()
alpha = {chr(97+i): [] for i in range(26)}
for i, s in enumerate(S):
    alpha[s].append(i+1)
n = len(S)
now = 0
ans = 0
for t in T:
    if alpha[t][-1] < now:
        ans += (n - now) + alpha[t][0]
        now = alpha[t][0]
    else:
        i = bisect_left(alpha[t], now+1)
        ans += alpha[t][i] - now
        now = alpha[t][i]
print(ans)
Problem p03068 (python)

Fixed submission:
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub('[^{}]'.format(s[k-1]), '*', s))

Buggy submission (verdict: Runtime Error):
from re import sub

n = int(input())
s = input()
k = int(input())

print(sub(f'[^{s[k-1]}]', '*', s))
Problem p03164 (python)

Fixed submission:
import sys


def solve():
    readline = sys.stdin.readline
    N, W = map(int, readline().split())
    WV = (map(int, readline().split()) for _ in range(N))
    INF = 10 ** 15
    MAX_V = 100 * 10**3 + 10
    dp = [INF] * MAX_V
    dp[0] = 0
    for w, v in WV:
        for i in range(MAX_V-1, v-1, -1):
            tmp_dp = dp[i-v] + w
            if dp[i] > tmp_dp:
                dp[i] = tmp_dp
    for v, w in enumerate(dp):
        if w <= W:
            ans = v
    return ans


if __name__ == "__main__":
    answer = solve()
    print(answer)

Buggy submission (verdict: Runtime Error):
import sys


def solve():
    readline = sys.stdin.readline
    N, W = map(int, readline().split())
    WV = (map(int, readline().split()) for _ in range(N))
    dp = [0] * (W+1)
    for w, v in WV:
        for i in range(W, w-1, -1):
            tmp_dp = dp[i-w] + v
            if dp[i] < tmp_dp:
                dp[i] = tmp_dp
    return max(dp)


if __name__ == "__main__":
    answer = solve()
    print(answer)