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

Fixed submission:
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
if len(counter) != 3:
    print("0")
    sys.exit()
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)

Buggy submission (verdict: Runtime Error):
import sys
from pprint import pprint

from collections import Counter
from math import factorial

def nCr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(sys.stdin.readline())
S = sys.stdin.readline().strip()
# print(len(S))

counter = Counter(S)
rgb_count = 0

max_width = len(S) // 2
for width in range(1, max_width+1):
    max_left = len(S) - 2 * width
    # print(width, max_left)
    for i in range(max_left):
        if len(set([S[i], S[i+width], S[i+2*width]])) == 3:
            rgb_count += 1


all_count = nCr(counter["R"], 1) * nCr(counter["G"], 1) * nCr(counter["B"], 1) 
# print(all_count, rgb_count)
print(all_count - rgb_count)
Problem p02742 (python)

Fixed submission:
import sys

H, W = map(int, sys.stdin.readline().strip().split())

if H == 1 or W == 1:
    print(1)
elif H % 2 == 0 or W % 2 == 0:
    print(H * W // 2)
else:
    print(H * W // 2 + 1)

Buggy submission (verdict: Runtime Error):
import sys
from pprint import pprint

H, W = map(int, sys.stdin.readline().strip().split())

if H % 2 == 0 or W % 2 == 0:
    print(H * W // 2)
else:
    print((H * W // 2 + 1)
Problem p02756 (python)

Fixed submission:
import sys
from pprint import pprint
from collections import deque

S = list(sys.stdin.readline().strip())
Q = int(sys.stdin.readline().strip())

q = deque(S)

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                #S = c + S
                q.appendleft(c)
            else:
                #S = S + c
                q.append(c)
        else:
            if n_rev % 2 == 0:
                #S = S + c
                q.append(c)
            else:
                #S = c + S
                q.appendleft(c)

S = "".join(list(q))
if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy submission (verdict: Runtime Error):
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                S = c + S
            else:
                S = S + s
        else:
            if n_rev % 2 == 0:
                S = S + c
            else:
                S = c + S

if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy submission (verdict: Runtime Error):
import sys
from pprint import pprint

S = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())

n_rev = 0
for _ in range(Q):
    tmp = sys.stdin.readline().strip().split()
    if tmp[0] == "1":
        n_rev += 1
    else:
        f, c = tmp[1], tmp[2]
        if f == "1":
            if n_rev % 2 == 0:
                S = c + S
            else:
                S = S + s
        else:
            if n_rev % 2 == 0:
                S = S + c
            else:
                S = c + S

if n_rev % 2 == 0:
    print(S)
else:
    print(S[::-1])
Problem p02780 (python)

Fixed submission:
import sys
from pprint import pprint

def solve(n, k, p):
    acum_E = [0]
    sum_E = 0
    for i, p_i in enumerate(p):
        sum_E += (1.0 + p_i)/2 
        acum_E.append(sum_E)
    # pprint(acum_E)
    
    ans = 0
    for i in range(n - k + 1):
        # print(i+k, i)
        ans = max(ans, acum_E[i + k] - acum_E[i])
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)

Buggy submission (verdict: Runtime Error):
def solve(n, k, p):
    E = [(1.0 + p_i)/2 for p_i in p]
    # pprint(E)
    
    ans = 0
    for i in range(n - k + 1):
        # print(i+3)
        ans = max(ans, sum([E[i+j] for j in range(k)]))
        # print(i, sum([E[i+j] for j in range(k)]))
    print(ans)

if __name__ == '__main__':
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    p = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, k, p)
Problem p02903 (python)

Fixed submission:
import sys

H, W, A, B = map(int, sys.stdin.readline().split())

for i in range(H):
    for j in range(W):
        if i < B:
            if j < A:
                print(0, end="")
            else:
                print(1, end="")
        else:
            if j < A:
                print(1, end="")
            else:
                print(0, end="")
    print("")

Buggy submission (verdict: Runtime Error):
import sys

H, W, A, B = map(int, sys.stdin.readline().split())

if B == 0:
    if W // 2 == A:
        for j in range(W):
            if i < A:
                print(1, end="")
            else:
                print(0, end="")
        print("")
    else:
        print("No")
elif H % B or W % A:
    print("No")
else:
    for i in range(H):
        for j in range(W):
            if (i // B) * A <= j < (i // B + 1)  * A:
                print(1, end="")
            else:
                print(0, end="")
        print("")
Problem p02936 (python)

Fixed submission:
from collections import deque


def solve(n, q, a, b, p, x):
    counter = [0] * n
    q_sum = [0] * n
    for i in range(q):
        q_sum[p[i]] += x[i]
    # pprint(q_sum)

    edges = {}
    for i in range(n-1):
        if a[i] not in edges:
            edges[a[i]] = []
        edges[a[i]].append(b[i])
    # pprint(edges)

    counter[0] = q_sum[0]
    children = deque()
    for child in edges[0]:
        counter[child] = q_sum[0]
        children.append(child)
    while children:
        child = children.popleft()
        counter[child] += q_sum[child]
        # print("child")
        # print(child, counter[child])
        if child in edges:
            for c in edges[child]:
                counter[c] = counter[child]
                # print("c")
                # print(c, counter[c])
                children.append(c)

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

if __name__ == "__main__":
    n, q = list(map(int, input().strip().split(" ")))
    a = []
    b = []
    for _ in range(n-1):
        a_i, b_i = list(map(int, input().strip().split(" ")))
        a.append(a_i - 1)
        b.append(b_i - 1)

    p = []
    x = []
    for _ in range(q):
        p_i, x_i = list(map(int, input().strip().split(" ")))
        p.append(p_i-1)
        x.append(x_i)
    solve(n, q, a, b, p, x)

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

N, Q = map(int, sys.stdin.readline().split(" "))

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().split(" "))
    # print(a, b)
    edges[a-1].append(b-1)
# print(edges)
# sys.exit()

points = [0] * N
for _ in range(Q):
    p, x = map(int, sys.stdin.readline().split(" "))
    points[p-1] += x


counted = [0] * N
q = deque([(0, points[0])])
while q:
    node, point = q.popleft()
    # print(node, point)
    counted[node] = str(point)
    for edge in edges[node]:
        q.appendleft((edge, point + points[edge]))

print(" ".join(counted))
Problem p02972 (python)

Fixed submission:
import sys

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

B = [-1 for _ in range(N)]
ans = []

for i in range(N, 0, -1):
    tmp_sum = 0
    tmp_i = 2 * i
    while N >= tmp_i :
        tmp_sum += B[tmp_i - 1]
        tmp_i += i

    # print(i, tmp_sum)
    if A[i-1] == tmp_sum % 2:
        B[i-1] = 0
    else:
        ans.append(i)
        B[i-1] = 1

print(len(ans))
if len(ans):
    print(" ".join(map(str, ans[::-1])))

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())
D = list(map(int, sys.stdin.readline().split()))

times = [0] * 24
for d in D:
    times[d] += 1

if max(times) > 2 or times[0] == 2 or times[12] == 2:
    print(0)
else:
    ans = 0
    # 1 - 11時間の時差の場合、Diと24 - Diの両方を試す
    for i in range(2**11):
        positions = []
        if times[0] == 1:
            positions.append(0)
        for j in range(11):
            if times[j+1] == 2:
                positions.append(j+1)
                positions.append(24 - j-1)
            elif times[j+1] == 1:
                if (i >> j) & 1:
                    positions.append(24 - j-1)
                else:
                    positions.append(j+1)
        if times[12] == 1:
            positions.append(12)
        positions.sort()
        # print(positions)
        lp = len(positions)
        d = float("inf")
        for p in range(lp):
            # 0をまたぐ場合がある
            if p == lp -1:
                diff = 24 - positions[p] + positions[0]
            else:
                diff = positions[p+1] - positions[p]
            d = min(d, diff if diff != 24 else 0)
        ans = max(ans, d)

print(ans)

Buggy submission (verdict: Runtime Error):

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

ans = [-1 for _ in range(N)]

count = 0
for i in range(N, 0, -1):
    tmp_sum = 0
    if N % i == 0 and N // i > 1:
        multi_max = N // i
        c = 1
        while multi_max > c:
            c += 1
            tmp_sum += ans[c * i - 1]

    # print(i, tmp_sum)
    if A[i-1] == 1:
        if tmp_sum % 2 == 0:
            count += 1
            ans[i-1] = 1
        else:
            ans[i-1] = 0
    else:
        if tmp_sum % 2 == 0:
            ans[i-1] = 0
        else:
            count += 1
            ans[i-1] = 1

print(count)
if count:
    print(" ".join(["1"] * count))
Problem p03067 (python)

Fixed submission:
import sys

def solve(a, b, c):
    if a > c > b or a < c < b:
        return 'Yes'
    return 'No'

if __name__ == '__main__':

    a, b, c = map(int, sys.stdin.readline().strip().split(" "))
    ans = solve(a, b, c)
    print ans

Buggy submission (verdict: Runtime Error):
import sys

def solve(N, S, K):
    char = S[K]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans
Problem p03068 (python)

Fixed submission:
import sys

def solve(N, S, K):
    char = S[K-1]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans

Buggy submission (verdict: Runtime Error):
import sys

def solve(N, S, K):
    char = S[K]

    ans = ''
    for i in xrange(len(S)):
        ans += S[i] if S[i] == char else '*'
    return ans

if __name__ == '__main__':

    N = sys.stdin.readline().strip()
    S = sys.stdin.readline().strip()
    K = sys.stdin.readline().strip()
    ans = solve(int(N), S, int(K))
    print ans
Problem p03074 (python)

Fixed submission:
import sys

N, K = map(int, sys.stdin.readline().strip().split())
S = sys.stdin.readline().strip()

l = x = ans = 0
for r in range(N):
    if S[r] == '0' :
        if r == 0 or S[r-1] == '1':
            x += 1
    if x > K:
        while S[l] == '1':
            l += 1
        while S[l] == '0':
            l += 1
        x -= 1
    ans = max(ans, r-l+1)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
S = list(input().strip())

comp = [0]
pre = S[0]
tmp = 0
for s_i in S:
    if s_i != pre:
        comp.append(tmp)
        tmp = 1
    else:
        tmp += 1
    
    pre = s_i
comp.append(tmp)
for i in range(len(comp)-1):
    comp[i+1] += comp[i]

ans = 1
if K == 1:
    w = 2
else:
    w = 2*K + 1
ans = 1
tmp = 0
c = 0
if K == 1:
    for i in range(2, len(comp)):
        tmp = comp[i] - comp[i-2]
        ans = max(ans, tmp)
else:
    start = 0 if S[0] == "1" else 1
    for i in range(start, len(comp), 2):
        tmp = comp[i] - comp[i-w-1]
        ans = max(ans, tmp)
print(ans)
Problem p03096 (python)

Fixed submission:
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1 for _ in range(2*10**5+1)]
dp = [0 for _ in range(N+5)]
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[c] = i

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()) - 1)

left = [-1 for _ in range(N+5)]
dp = [0 for _ in range(N+5)]
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[c] = i

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()) - 1)

left = [-1 for _ in range(N)]
dp = [0 for _ in range(N+1)]
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[c] = i

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1 for _ in range(N+1)] # 1-indexed
dp = [0 for _ in range(N+1)]
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[c] = i

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1] * (N+1) # 1-indexed
dp = [0] * (N+1)
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[stones[i]] = i

print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1] * (N+1) # 1-indexed
dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    dp[i] = dp[i-1]
    # 同じ色が前回出現した位置
    if left[stones[i-1]] != -1 and left[stones[i-1]] != i - 1:
        dp[i] += dp[left[stones[i-1]]]
    
    left[stones[i-1]] = i

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1] * N
dp = [0] * (N+1)
dp[0] = 1
for i in range(1, N+1):
    dp[i] = dp[i-1]
    # 同じ色が前回出現した位置
    if left[stones[i-1]] != -1 and left[stones[i-1]] != i - 1:
        dp[i] += dp[left[stones[i-1]]]
    
    left[stones[i-1]] = i

print(dp[-1])
Problem p03311 (python)

Fixed submission:
import sys

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

A_dash = []
for i in range(N):
    A_dash.append(A[i] - (i + 1))

A_dash.sort()
ans = -float("inf")
if N % 2 == 1:
    tmp = 0
    b = A_dash[N // 2]
    for i in range(N):
        tmp += abs(A_dash[i] - b)
    print(tmp)
else:
    tmp1 = 0
    b = A_dash[N // 2 - 1]
    for i in range(N):
        tmp1 += abs(A_dash[i] - b)
    
    tmp2 = 0
    b = A_dash[N // 2]
    for i in range(N):
        tmp2 += abs(A_dash[i] - b)
    print(min(tmp1, tmp2))

Buggy submission (verdict: Runtime Error):
import sys

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

A_dash = []
for i in range(N):
    A_dash.append(A[i] - (i + 1))

A_dash.sort()
ans = -float("inf")
if N % 2 == 0:
    tmp = 0
    b = A_dash[N // 2]
    for i in range(N):
        tmp += abs(A_dash[i] - b)
    print(tmp)
else:
    tmp1 = 0
    b = A_dash[N // 2]
    for i in range(N):
        tmp1 += abs(A_dash[i] - b)
    
    tmp2 = 0
    b = A_dash[N // 2 + 1]
    for i in range(N):
        tmp2 += abs(A_dash[i] - b)
    print(min(tmp1, tmp2))
Problem p03352 (python)

Fixed submission:
import sys
 
X = int(sys.stdin.readline())
ans = 0
for i in range(X+1):
    for j in range(2, 11):
        tmp = pow(i, j)
        if tmp <= X:
            ans = max(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

X = int(sys.stdin.readline())
ans = 0
for i in range(X+1):
  	for j in range(11):
      	tmp = pow(i, j)
        if tmp <= X:
          	ans = max(ans, tmp)
print(ans)
Problem p03419 (python)

Fixed submission:
import sys

N, M = map(int, sys.stdin.readline().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    two = 2
    three = N * M - two
    print(three)
else:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)

Buggy submission (verdict: Runtime Error):
if N > 1 and M > 1:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)
else:
    two = 2
    three = N * M - two
    print(three)
Problem p03436 (python)

Fixed submission:
import sys
from pprint import pprint

from collections import deque

h, w = map(int, sys.stdin.readline().strip().split(" "))

field = []
for _ in range(h):
    field.append(list(sys.stdin.readline().strip()))

black = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            black += 1

def bfs(field, h, w, sy, sx, gy, gx):
    q = deque()
    q.append((0, sy, sx))
    visited = set()
    while q:
        count, y, x = q.popleft()
        for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            if 0 <= y+dy < h and 0 <= x+dx < w:
                if field[y+dy][x+dx] == "#":
                    continue
                elif (y+dy, x+dx) in visited:
                    continue
                elif (y+dy, x+dx) == (h-1, w-1):
                    return count+1

                visited.add((y+dy, x+dx))
                q.append((count+1, y+dy, x+dx))
    return -1

shortest = bfs(field, h, w, 0, 0, h-1, w-1)
# print(shortest)
if shortest == -1:
    print(-1)
else:
    print(h*w - black - (shortest+1))

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

H, W = map(int, sys.stdin.readline().split())

grid = []
for _ in range(W):
    grid.append(sys.stdin.readline().strip())

black = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            black += 1

q = deque()
q.append((0, 0, 0))
visited = set()
while q:
    x, y, c = q.popleft()
    if x == W-1 and y == H-1:
        break
    if (x, y) in visited:
        continue
    visited.add((x, y))

    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < W and 0 <= ny < H and grid[ny][nx] != "#":
                q.append((nx, ny, c+1))

if x == W-1 and y == H-1:
    print(H*W - black - c - 1)
else:
    print(-1)
Problem p03488 (python)

Fixed submission:
import sys

s = sys.stdin.readline().strip()
x, y = map(int, sys.stdin.readline().split())

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
x_init = -1
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            if x_init == -1:
                x_init = d
            else:
                dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    cand = set()
    if mode == "x":
        cand.add(x_init)
    else:
        cand.add(0)
    for i in range(len_d):
        next_cand = set()
        for d in cand:
            next_cand.add(d + dist[mode][i])
            next_cand.add(d - dist[mode][i])
        cand = next_cand

    if goal[mode] not in cand:
        print("No")
        sys.exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

s = sys.stdin.readline().strip()
x, y = map(int, sys.stdin.readline().split())

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    # dp[len_d][grid]
    dp = [[0 for _ in range(16005)] for _ in range(len_d+1)]
    # print(dp)
    dp[0][8000] = 1
    for i in range(len_d):
        for j in range(16005):
            if dp[i][j] == 0:
                continue
            # +に進む
            # print(dist[mode][i])
            dp[i+1][j + dist[mode][i]] += dp[i][j]
            # -に進む
            dp[i+1][j - dist[mode][i]] += dp[i][j]

    if dp[i+1][goal[mode] + 8000] == 0:
        print("No")
        sys.exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
import sys

s = sys.stdin.readline().strip()
x, y = map(int, sys.stdin.readline().split())

goal = {"x": x, "y": y}
dist = {"x": [], "y": []}

if s[-1] != "T":
    s += "T"
d = 0
f = 0
for i in s:
    if i == "F":
        d += 1
    else:
        if f % 2 == 0:
            dist["x"].append(d)
        else:
            dist["y"].append(d)
        d = 0
        f += 1

# print(dist)
for mode in ("x", "y"):
    len_d = len(dist[mode])
    # dp[len_d][grid]
    dp = [[0 for _ in range(16005)] for _ in range(len_d+1)]
    # print(dp)
    dp[0][8000] = 1
    for i in range(len_d):
        for j in range(16005):
            if dp[i][j] == 0:
                continue
            # +に進む
            # print(dist[mode][i])
            dp[i+1][j + dist[mode][i]] += dp[i][j]
            # -に進む
            dp[i+1][j - dist[mode][i]] += dp[i][j]

    if dp[i+1][goal[mode] + 8000] == 0:
        print("No")
        sys.exit()

print("Yes")
Problem p03565 (python)

Fixed submission:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

cand = []
for i in range(0, len_s - len_t + 1):
    a = list(s)
    flag = True
    for j in range(len_t):
        # print(s[i+j], t[j])
        if s[i+j] == "?":
            a[i+j] = t[j]
        elif s[i+j] != t[j]:
            flag = False
            break
    if flag:
        cand.append(a)

if cand:
    print("".join(cand[-1]).replace("?", "a"))
    sys.exit()
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

for i in range(0, len_s - len_t + 1):
    flag = True
    for j in range(len_t):
        if flag == False:
            continue
        # print(s[i+j], t[j])
        if s[i+j] == "?" or s[i+j] == t[j]:
            continue
        flag = False
        break
    if flag:
        ans = ""
        for k, s_k in enumerate(s):
            if i < k <= i + len_t:
                ans += t[k-i]
            else:
                if s_k == "?":
                    ans += "a"
                else:
                    ans += s_k
        print(ans)        
        sys.exit()

print("UNRESTORABLE")