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

Fixed submission:
# classを使うのをやめてlistで実施する
from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
import sys
input = sys.stdin.readline

def dfs(v):
    visited[v] = True
    for i in range(len(AL[v][CHILDREN])):
        u = AL[v][CHILDREN][i]
        if visited[u]:
            AL[v][CHILDREN][i] = None
            continue
        AL[v][SIZE] += dfs(u)
    return AL[v][SIZE]


def anaaki(v):
    ret = powp - 1
    for ch in AL[v][CHILDREN]:
        if ch is None: continue
        ret -= pow(2, AL[ch][SIZE], p) - 1
        ret %= p
    ret -= pow(2, n - AL[v][SIZE], p) - 1
    ret %= p
    return ret

n = int(input())
SIZE = 0
CHILDREN = 1
AL = [[1, []] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
powp = pow(2, n - 1, p)

for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    AL[a][CHILDREN].append(b)
    AL[b][CHILDREN].append(a)

dfs(0)
numer = 0
for i in range(n):
    numer += anaaki(i)
    numer %= p

denom = pow(2, n, p)
print(numer * pow(denom, p - 2, p) % p)

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

class Node:
    def __init__(self):
        self.size = 1  # 自分以下のノードの数
        self.children = []

def dfs(v):
    V = Node()
    visited[v] = True
    for u in AL[v]:
        if visited[u]: continue
        U = dfs(u)
        V.size += U.size
        V.children.append(U)
    return V

def anaaki(V):
    ret = pow(2, n - 1, p) - 1
    for ch in V.children:
        ret -= pow(2, ch.size) - 1
        ret %= p
    ret -= pow(2, n - V.size) - 1
    ret %= p
    return ret

n = int(input())
AL = [[] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
for i in range(n - 1):
    a, b = [int(x) - 1 for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

# dfs
root = dfs(0)
que = deque([root])
numer = 0
while que:
    next = que.popleft()
    numer += anaaki(next)
    numer %= p
    for ch in next.children:
        que.append(ch)

denom = pow(2, n, p)

print( numer * pow(denom, p - 2, p) % p)
Problem p02866 (python)

Fixed submission:
import numpy as np

N = int(input())
D = np.array([int(a) for a in input().split()])

num_at_dist = np.array([1] + [0] * (N-1) + [0]) # extra 0 at the end for index -1

if D[0] != 0:
    ans = 0
else:
    ans = 1
    D = np.sort(D)
    for i in range(1, N):
        dist = D[i]
        num_at_dist[dist] += 1
        ans = ( ans * num_at_dist[dist - 1] ) % 998244353

print(ans % 998244353)

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

N = int(input())
D = np.array([int(a) for a in input().split()])

num_at_dist = np.array([1] + [0] * (N-1) + [0]) # extra 0 at the end for index -1

if D[0] != 0:
    ans = 0
else:
    ans = 1
    D = np.sort(D)
    for i in range(1, N):
        dist = D[i]
        num_at_dist[dist] += 1
        ans *= num_at_dist[dist - 1]

print(ans % 998244353)
Problem p02900 (python)

Fixed submission:
### Pythonのバージョンが3.4.3なのでmath.gcd(*, *)がエラーとなるらしい。
import fractions
import math

def prime_factorization(n):
    s = math.floor(math.sqrt(n)) # 平方根を小数点切り捨て
    ans = [] # [素数, 指数]のリスト

    # 2からsまでの素因数を求める
    for i in [2] + list(range(3, s + 1, 2)):
        if n < i:
            break
        if n % i == 0:
            r = 0 # 指数カウンタクリア
            while n % i == 0:
                r += 1
                n //= i
            ans.append([i, r])

    # 残った素数を追加
    if n > s:
        ans.append([n, 1])

    return(ans)


A, B = [int(a) for a in input().split()]

# d = gcd(A, B) = p_1^(e_1) + p_2^(e_2) + ... + p_k^(e_k)
# と素因数分解できる場合、答えは k + 1
d = fractions.gcd(A, B)
pf = prime_factorization(d)
print(len(pf) + 1)

Buggy submission (verdict: Runtime Error):
### Pythonのバージョンが3.4.3なのでmath.gcd(*, *)がエラーとなるらしい。
from fractions import gcd

def prime_factorization(n):
    s = math.floor(math.sqrt(n)) # 平方根を小数点切り捨て
    ans = [] # [素数, 指数]のリスト

    # 2からsまでの素因数を求める
    for i in [2] + list(range(3, s + 1, 2)):
        if n < i:
            break
        if n % i == 0:
            r = 0 # 指数カウンタクリア
            while n % i == 0:
                r += 1
                n //= i
            ans.append([i, r])

    # 残った素数を追加
    if n > s:
        ans.append([n, 1])

    return(ans)


A, B = [int(a) for a in input().split()]

# d = gcd(A, B) = p_1^(e_1) + p_2^(e_2) + ... + p_k^(e_k)
# と素因数分解できる場合、答えは k + 1
d = gcd(A, B)
pf = prime_factorization(d)
print(len(pf) + 1)

Buggy submission (verdict: Runtime Error):
import math

def prime_factorization(n):
    s = math.floor(math.sqrt(n)) # 平方根を小数点切り捨て
    ans = [] # [素数, 指数]のリスト

    # 2からsまでの素因数を求める
    for i in [2] + list(range(3, s + 1, 2)):
        if n < i:
            break
        if n % i == 0:
            r = 0 # 指数カウンタクリア
            while n % i == 0:
                r += 1
                n //= i
            ans.append([i, r])

    # 残った素数を追加
    if n > s:
        ans.append([n, 1])

    return(ans)


A, B = [int(a) for a in input().split()]

# d = gcd(A, B) = p_1^(e_1) + p_2^(e_2) + ... + p_k^(e_k)
# と素因数分解できる場合、答えは k + 1
d = math.gcd(A, B)
pf = prime_factorization(d)
print(len(pf) + 1)

Buggy submission (verdict: Runtime Error):
import math

def prime_factorization(n):
    s = math.floor(math.sqrt(n)) # 平方根を小数点切り捨て
    ans = [] # [素数, 指数]のリスト

    # 2からsまでの素因数を求める
    for i in [2] + list(range(3, s + 1, 2)):
        if n < i:
            break
        if n % i == 0:
            r = 0 # 指数カウンタクリア
            while n % i == 0:
                r += 1
                n //= i
            ans.append([i, r])

    # 残った素数を追加
    if n > s:
        ans.append([n, 1])

    return(ans)


A, B = [int(a) for a in input().split()]

# d = gcd(A, B) = p_1^(e_1) + p_2^(e_2) + ... + p_k^(e_k)
# と素因数分解できる場合、答えは k + 1
d = math.gcd(A, B)
pf = prime_factorization(d)
print(len(pf) + 1)
Problem p02911 (python)

Fixed submission:
N, K, Q = input().strip().split()
N, K, Q = [int(N), int(K), int(Q)]
A = [0] * (Q+1)  # index調整のため、長さQ+1のリストとする
for i in range(1, Q+1):
    A[i] = int(input())

# まず、全員が毎回負けた場合の点数は
points = [K - Q] * (N+1)

for i in range(1, Q+1): # 各ラウンドについて勝者に+1ポイント与える
    points[A[i]] += 1

for i in range(1, N+1):
    print('Yes' if points[i] > 0 else 'No')

Buggy submission (verdict: Runtime Error):
N, K, Q = input().strip().split()
N, K, Q = [int(N), int(K), int(Q)]
A = [0] * (Q+1)  # index調整のため、長さQ+1のリストとする
for i in range(1, Q+1):
    A[i] = int(input())

# まず、全員が毎回負けた場合の点数は
points = [K - Q] * (N+1)

for i in range(1, Q+1) # 各ラウンドについて勝者に+1ポイント与える
    points[A[i]] += 1

for i in range(1, N+1):
    print('Yes' if points[i] > 0 else 'No')
Problem p02917 (python)

Fixed submission:
# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換

sum = 0
for i in range(1, N + 1): # i = 1, 2, ..., N
    sum += min(B[i-1], B[i]) # A[i] <= min(B[i-1], B[i])

print(sum)

Buggy submission (verdict: Runtime Error):
# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換


for i in range(1, N + 1): # i = 1, 2, ..., N
    sum += min(B[i-1], B[i]) # A[i] <= min(B[i-1], B[i])

print(sum)
Problem p02936 (python)

Fixed submission:
# 20/5/28
from collections import deque

N, Q = [int(x) for x in input().split()]
AL = [[] for _ in range(N + 1)]
for i in range(1, N):
    a, b = [int(x) for x in input().split()]
    AL[a].append(b)
    AL[b].append(a)

cnt = [0] * (N + 1)
for j in range(Q):
    p, x = [int(x) for x in input().split()]
    cnt[p] += x

visited = [False] * (N + 1)
stk = deque([1])
while stk:
    root = stk.pop()
    visited[root] = True
    for v in AL[root]:
        if not visited[v]:
            cnt[v] += cnt[root]
            stk.append(v)

s = " ".join(map(str, cnt[1:]))
print(s)

Buggy submission (verdict: Runtime Error):
class RootedTree():
    def __init__(self, N, root = 1):
        # N is the number of nodes
        # self.nodes is a list of TreeNode
        self.nodes = [None] * (N + 1) # self.nodes[0] is kept None
        self.root = root
        self.N = N # number of nodes

    def add_node(self, tree_node, num):
        self.nodes[num] = tree_node

    def add_val(self, p, x, Q):
        for j in range(1, Q + 1):
            self._add_val(p[j], x[j])

    def _add_val(self, p_val, x_val):
        self.nodes[p_val].increment_counter(x_val)
        for ch in self.nodes[p_val].children:
            self._add_val(ch, x_val)

    def print_counter(self):
        for i in range(1, N):
            print("{} ".format(self.nodes[i].counter), end = "")
        print("{} ".format(self.nodes[N].counter))

class TreeNode():
    def __init__(self, num):
        self.number = num  # integer (vertex number)
        self.counter = 0
        self.children = set()

    def add_child(self, v):
        self.children.add(v)

    def increment_counter(self, x):
        self.counter += x

class Graph():
    def __init__(self, N):
        self.AL = [None] + [set() for i in range(N)] # adjacency list
        self.N = N # number ov vertices

    def add_edge(self, u, v):
        self.AL[u].add(v)
        self.AL[v].add(u)

    def to_rooted_tree(self):
        rooted_tree = RootedTree(self.N, 1)
        self._to_rooted_tree(1, {1}, rooted_tree)
        return rooted_tree

    def _to_rooted_tree(self, v, visited, rooted_tree):
        node = TreeNode(v)
        rooted_tree.add_node(node, v)

        for u in self.AL[v]: # leaf has only one neighbour (parent)
            if not u in visited:
                visited.add(u)
                node.add_child(u)
                self._to_rooted_tree(u, visited, rooted_tree)


# input
N, Q = [int(k) for k in input().split()]
a = [None] * N # a[0] = None
b = [None] * N # b[0] = None
for i in range(1, N):
    a[i], b[i] = [int(k) for k in input().split()]
p = [None] * (Q + 1)
x = [None] * (Q + 1)
for i in range(1, Q + 1):
    p[i], x[i] = [int(k) for k in input().split()]

# create a graph
G = Graph(N)
for i in range(1, N):
    G.add_edge(a[i], b[i])

# run depth first search to form a rooted tree
T = G.to_rooted_tree()


T.add_val(p, x, Q)
T.print_counter()
Problem p02953 (python)

Fixed submission:
N = int(input())
H = [int(h) for h in input().split()]

# 状態
INCREASING = 1
DECREASED_BY_1 = 2
FAIL = -1

state = INCREASING

for i in range(1, N): # i = 1, 2, ..., N - 1
    if state == INCREASING:
        if H[i] == H[i - 1] - 1: # 1減少
            state = DECREASED_BY_1
        elif H[i] <= H[i - 1] - 2: # 2以上減少
            state = FAIL
    elif state == DECREASED_BY_1:
        if H[i] > H[i - 1]: # 増加
            state = INCREASING
        elif H[i] < H[i - 1]: # 減少
            state = FAIL
    else:
        break

ans = "Yes" if state is not FAIL else "No"
print(ans)

Buggy submission (verdict: Runtime Error):
from enum import Enum

N = int(input())
H = [int(h) for h in input().split()]

# 状態
class State(Enum):
    INCREASING = 1
    DECREASED_BY_1 = 2
    FAIL = -1

state = State.INCREASING

for i in range(1, N): # i = 1, 2, ..., N - 1
    if state == State.INCREASING:
        if H[i] == H[i - 1] - 1: # 1減少
            state = State.DECREASED_BY_1
        elif H[i] <= H[i - 1] - 2: # 2以上減少
            state = State.FAIL
    elif state == State.DECREASED_BY_1:
        if H[i] > H[i - 1]: # 増加
            state = State.INCREASING
        elif H[i] < H[i - 1]: # 減少
            state = State.FAIL
    else:
        break

ans = "Yes" if state is not State.FAIL else "No"
print(ans)
Problem p02960 (python)

Fixed submission:
p = 10**9 + 7
S = input()
N = len(S)

dp = [[0 for _ in range(13)] for _ in range(2)]
dp[0][0] = 1 # i = N - 1のケースでうまくいくための処置
r = 0

for i in range(N - 1,  -1,  -1):  # 小さい桁から順に
    w = 1 if i == N - 1 else (w * 10) % 13 # 各桁の重み
    r = 1 - r  # dpの0行目と1行目を交互に使う
    if S[i] == '?':
        for j in range(13):
            for k in range(10): # ?の値が0, 1, ..., 9のとき
                dp[r][(j + w * k) % 13] += dp[1 - r][j]
                if dp[r][(j + w * k) % 13] >= p:
                    dp[r][(j + w * k) % 13] -= p
    else:
        k = int(S[i])
        for j in range(13):
            dp[r][(j + w * k) % 13] = dp[1 - r][j]

    dp[1 - r] = [0] * 13

print(dp[r][5])

Buggy submission (verdict: Runtime Error):
S = input()
p = 10**9 + 7

N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N + 1)]
dp[N][0] = 1 # i = N - 1のケースでうまくいくための処置

for i in range(N - 1,  -1,  -1):  # 小さい桁から順に
    w = 1 if i == N - 1 else (w * 10) % 13 # 各桁の重み

    if S[i] is not '?':
        k = int(S[i])
        for j in range(13):
            dp[i][(j + w * k) % 13] = dp[i + 1][j]
    else:
        for j in range(13):
            for k in range(10): # ?の値が0, 1, ..., 9のとき
                dp[i][(j + w * k) % 13] = (dp[i][(j + w * k) % 13] + dp[i + 1][j]) % p

print(dp[0][5])
Problem p03014 (python)

Fixed submission:
H, W = [int(a) for a in input().split()]
S = [None] * H
for i in range(H):
    S[i] = input()

L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]

ans = 0

# L, R, Uを求める
for i in range(H):
    for j in range(W):

        if S[i][j] == '#':
            pass  # L, R, Uは0で初期化されている
        else:
            # Uを求める
            if i == 0:  U[i][j] = 1
            else:       U[i][j] = U[i - 1][j] + 1

            # Lを求める
            if j == 0:  L[i][j] = 1
            else:       L[i][j] = L[i][j - 1] + 1

        # Rを求める
        if S[i][W - 1 - j] == '#':
            pass
        elif j == 0:
            R[i][W - 1 - j] = 1
        else:
            R[i][W - 1 - j] = R[i][W - j] + 1

# Dを求める
for i in range(H - 1, -1, -1):
    for j in range(W):
        if S[i][j] == '#':  pass
        elif i == H - 1:    D[i][j] = 1
        else:               D[i][j] = D[i + 1][j] + 1
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = [int(a) for a in input().split()]
S = [None] * H
for i in range(H):
    S[i] = input()

L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]

ans = 0

for i in range(H):
    for j in range(W):
        # Uを求める
        if S[i][j] == '#':  pass  # Uは0で初期化されている
        elif i == 0:        U[i][j] = 1
        else:               U[i][j] = U[i - 1][j] + 1

        # Dを求める
        if S[H - 1 - i][j] == '#':  pass
        elif i == 0:    D[i][j] = 1
        else:           D[i][j] = D[i + 1][j] + 1

        # Lを求める
        if S[i][j] == '#':  pass
        elif j == 0:  L[i][j] = 1
        else:       L[i][j] = L[i][j - 1] + 1

        # Rを求める
        if S[i][W - 1 - j] == '#':  pass
        elif j == 0:    R[i][W - 1 - j] = 1
        else:           R[i][W - 1 - j] = R[i][W - j] + 1

        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
        
print(ans)
Problem p03087 (python)

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

cnt = [0] * 200010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 200010
flag = [0] * 200010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 :
        ans -= 1
    print("{}".format(ans))

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

cnt = [0] * 20010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 20010
flag = [0] * 20010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))

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

cnt = [0] * 10010

for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        cnt[i] += 1

s = [0] * 10010
flag = [0] * 10010
for i in range(len(cnt) - 1):
    if cnt[i] > 0 :
        flag[i + 1] = 1
    s[i + 1] = s[i] + cnt[i]

for i in range(Q):
    l, r = map(int, input().split())
    ans = s[r] - s[l - 1]
    if flag[r] != 0 : ans -= 1
    print("{}".format(ans))
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1 :
    print("Hello World")
else :
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1 :
    print("Hello World")
if n == 2 :
    a, b = map(int, input().split())
    print(a + b)
Problem p02632 (python)

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

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2 == 1:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 2000005
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
k = int(input())
s = input()

mod = 10**9+7

def fpow(x, y):
  res = 1
  while y>0:
    if y%2:
      res = (res%mod * x%mod)%mod
    x = (x%mod * x%mod)%mod
    y = y//2
  return res
MAXN = 10**6+5
fact = [0]*MAXN
fact[0] = 1
for i in range(1, MAXN):
  fact[i] = (i%mod * fact[i-1]%mod)%mod
  
def inv(a):
  return fpow(a, mod-2)
  
n = len(s)
ans = fpow(26, n+k)
for m in range(n):
    ncm = (fact[n+k]%mod * inv(fact[m])%mod)%mod
    ncm = (ncm%mod * inv(fact[n+k-m])%mod)%mod
    
    p = fpow(25, n+k-m)
    
    val = (ncm%mod * p%mod)%mod
    
    ans = (ans%mod - val%mod + mod)%mod
print(ans%mod)
Problem p02658 (python)

Fixed submission:
n = int(input())
arr = list(map(int,input().split()))
if 0 in arr:
    print(0)
else:
    res = 1
    flag = 0
    for i in arr:
        res = res*i
        if res>10**18:
            flag = 1
            break
    if flag==1:
        print(-1)
    else:
        print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = map(int, input().split())
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
		break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
		break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = list(map(int, input().split()))
zero = False
ans = 1
ok = True
for e in arr:
	if e == 0:
		zero = True
        break
	ans = ans * e;
	if ans > 10**18:
		ok = False
        break
if zero:
	print(0)
else:
	if ok:
		print(ans)
	else:
		print(-1)
Problem p02630 (python)

Fixed submission:
from collections import Counter
n = int(input())
lis = list(map(int,input().split()))
l = Counter(lis)
d = [0]+[l[i+1] for i in range(10**5)]
q = int(input())
s = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    if d[a]!=0:
        temp = d[a]
        d[a]=0
        d[b]+=temp
        s += temp*(b-a)
    print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int,input().split()))
q = int(input())
x = {}
for i in lis:
    if i not in x:
        x[i]=1
    else:
        x[i]+=1
total = sum(lis)
for i in range(q):
    a,b=map(int,input().split())
    diff = b-a
    total += diff*x[a]
    x[b]+=x[a]
    print(total)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
flag=0
if s in t:
  if(len(t)-len(s)==1 and s[0]==t[0]):
    flag=1
print("Yes") if(flag) else print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
flag=0
if s in t:
  if(len(t)-len(s)=1 and s[0]==t[0]):
    flag=1
print("Yes") if(flag) else print("No")
Problem p03160 (python)

Fixed submission:
from types import GeneratorType
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc
n = int(input())
lis = list(map(int, input().split()))
dp = {}
@bootstrap
def TD(i):
    if i == n - 1:
        yield 0

    if i in dp:
        yield dp[i]
    mi = float('inf')
    for j in range(1, 3):
        if i + j < n:
            tmp = yield TD(i+j)
            mi = min(mi, abs(lis[i] - lis[i+j])+ tmp)
    dp[i] = mi
    yield mi
print(TD(0))

Buggy submission (verdict: Runtime Error):
n = int(input())
lis = list(map(int, input().split()))
dp = {}
def TD(i):
    if i == n - 1:
        return 0

    if i in dp:
        return dp[i]
    mi = float('inf')
    for j in range(1, 3):
        if i + j < n:
            mi = min(mi, abs(lis[i] - lis[i+j])+TD(i+j))
    dp[i] = mi
    return mi
print(TD(0))