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

Fixed submission:
n=int(input())
w=[]
ans='Yes'
for i in range(n):
    w.append(list(input()))
    if i==0:
        continue
    if w[i][0]!=w[i-1][len(w[i-1])-1]:
            ans='No'
            break
    for j in range(i):
        if w[i]==w[j]:
            ans='No'
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=abs(x-a[0])
cnt=abs(a[1]-a[0])
for j in range(n-1):
    cnt=min(abs(a[j+1]-a[j]),cnt)
for i in range(n):
    ans=min(abs(x-a[i]),ans)
print(min(ans,cnt))
Problem p03273 (python)

Fixed submission:
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
j=0
lis=[]
l=[]
count=0
for i in range(h):
    for j in range(w):
        if a[i][j]!='.':
            break
        if j==w-1:
            l.append(i)
x=0
while x<len(l):
    del a[l[x]-count]
    count+=1 
    x+=1
#print(a)
for k in range(len(a)):
    for l in range(w):
        if a[k][l]=='.':
            c=0
            while c<len(a):
                if a[c][l]!='.':
                    break
                if c==len(a)-1 and l not in set(lis):
                    lis.append(l)
                c+=1
ans=''
#print(lis)
tmp=0
count=0
for o in range(len(lis)):
    tmp=lis[o]
    for s in range(len(a)):
        del a[s][tmp-count]
    count+=1    
for q in range(len(a)):
    for e in range(len(a[0])):
        ans+=a[q][e]
    print(ans)
    ans=''

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
j=0
lis=[]
while j<len(a):
    if '#' not in set(a[j]):
        a.remove(a[j])
    j+=1
for k in range(len(a)):
    for l in range(w):
        if a[k][l]=='.':
            c=0
            while c<len(a):
                if a[c][l]!='.':
                    break
                if c==len(a)-1 and l not in set(lis):
                    lis.append(l)
                c+=1
ans=''
#print(lis)
tmp=0

for o in range(len(lis)):
    tmp=lis[o]
    for s in range(len(a)):
        del a[s][tmp]
for q in range(len(a)):
    for e in range(len(a[0])):
        ans+=a[q][e]
    print(ans)
    ans=''
Problem p03294 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print(sum(a)-n)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(int,input().split())
print(sum(a)-n)
Problem p03351 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
if abs(a-c)<=d:
    print('Yes')
elif abs(a-b)<=d and abs(b-c)<=d:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
if abs(a-c)<=d:
    print('Yes')
elif abs(a-b)<=d and abs(b-c)<=d:
    print('Yes')
else:
    print('No')
Problem p03352 (python)

Fixed submission:
# coding: utf-8
# Your code here!
x=int(input())
ans=[]
if x==1:
    print(1)
else:
    for i in range(1,x+1):
        for j in range(2,x+1):
            if i**j<=x:
                ans.append(i**j)
            else:
                break
    ans.sort(reverse=True)
    print(ans[0])
#print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
x=int(input())
ans=[]
for i in range(1,x+1):
    for j in range(2,x+1):
        if i**j<=x:
            ans.append(i**j)
        else:
            break
ans.sort(reverse=True)
print(ans[0])
#print(ans)
Problem p03427 (python)

Fixed submission:
n=int(input())
k=list(str(n))
ans=0
for i in range(len(k)):
    k[i]=int(k[i])
print(max(sum(k),9*len(k)-9+k[0]-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
k=list(str(n))
ans=0
print(max(sum(k),9*len(k)-9+k[0]-1))
Problem p03471 (python)

Fixed submission:
n,y=map(int,input().split())
ans=[-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    if y-10000*i-5000*j==1000*(n-i-j):
      ans=[i,j,n-i-j]
      print(ans[0],ans[1],ans[2])
      exit()
print(ans[0],ans[1],ans[2])

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
ans=[-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    if y-10000*i-5000*j==1000*(n-i-j):
      ans=[i,j,n-i-j]
      print(ans[1],ans[2],ans[3])
      exit()
print(ans[1],ans[2],ans[3])

Buggy submission (verdict: Runtime Error):
n,y=map(int,input().split())
ans=[-1,-1,-1]
for i in range(n+1):
  for j in range(n-i+1):
    if y-10000＊i-5000＊j==1000＊(n-i-j):
      ans=[i,j,n-i-j]
      print(ans[1],ans[2],ans[3])
      exit()
print(ans[1],ans[2],ans[3])
Problem p03501 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(min(a*b,c))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(min(a*b,c)
Problem p03523 (python)

Fixed submission:
import copy
s=list(input())
if len(s)>=10 or len(s)<=3:
    print('NO')
else:
    n=len(s)
    cnt=''.join(s)
    ans=[cnt]
    for i in range(2**(n+1)):
        c=copy.deepcopy(s)
        cc=0
        #print(c)
        for j in range(n+1):
            if (i >> j) & 1:
                c.insert(j+cc,'A')
                cc+=1
        cnt=''.join(c)
        ans.append(cnt)
    if 'AKIHABARA'in ans:
        print('YES')
    else:
        print('NO')
    #print(ans)

Buggy submission (verdict: Runtime Error):
s=list(input())
if s.count('K')==1 and s.count('I')==1 and s.count('H')==1 ands.count('B')==1 ands.count('R')==1:
    print('YES')
else:
    print('NO')
Problem p03729 (python)

Fixed submission:
a,b,c=input().split()
a=list(a)
b=list(b)
c=list(c)
if a[len(a)-1]==b[0] and b[len(b)-1]==c[0]:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
a=list(a)
b=list(b)
c=list(c)
if a[len(a)]==b[0] and b[len(b)]==c[0]:
  print('YES')
else:
  print('NO')
Problem p03737 (python)

Fixed submission:
a,b,c=input().split()
a=list(a)
b=list(b)
c=list(c)
print(a[0].upper()+b[0].upper()+c[0].upper())

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
a=list(a)
b=list(b)
c=list(c)
print(a[0].upper+b[0].upper+c[0].upper)
Problem p03807 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if a[i]%2!=0:
        c+=1
if c%2==0:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int.input().split()))
c=0
for i in range(n):
    if a[i]%2!=0:
        c+=1
if c%2==0:
    print('YES')
else:
    print('NO')
Problem p03844 (python)

Fixed submission:
a,b,c=input().split()
a=int(a)
c=int(c)
if b=='-':
  print(a-c)
else:
  print(a+c)

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
a=int(a)
b=int(b)
if b=='-':
  print(a-c)
else:
  print(a+b)
Problem p03957 (python)

Fixed submission:
s=list(input())
ans=0
for i in range(len(s)):
    if s[i]=='C':
        ans+=1
        break
for j in range(i,len(s)):
    if s[j]=='F':
        ans+=1
        break
if ans==2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=list(input())
ans=0
for i in range(len(s)):
  if ans==2:
    break
  if s[i]=='C':
    ans+=1
  if ans=1:
    if s[i]=='F':
      ans+=1
if ans==2:
  print('Yes')
else:
  print('No')
Problem p03998 (python)

Fixed submission:
sa=list(input())
sb=list(input())
sc=list(input())
cnt=sa[0]
sa.remove(sa[0])
while len(sa)!=0 or len(sb)!=0 or len(sc)!=0:
    #print(sa,sb,sc)
    if cnt=='a':
        if sa!=[]:
            cnt=sa[0]
            sa.remove(sa[0])
    elif cnt=='b':
        if sb!=[]:
            cnt=sb[0]
            sb.remove(sb[0])
    elif cnt=='c':
        if sc!=[]:
            cnt=sc[0]
            sc.remove(sc[0])
    if len(sa)==0 and cnt=='a':
        print("A")
        break
    elif len(sb)==0 and cnt=='b':
        print("B")
        break
    elif len(sc)==0 and cnt=='c':
        print("C")
        break

Buggy submission (verdict: Runtime Error):
sa=list(input())
sb=list(input())
sc=list(input())
cnt=sa[0]
sa.remove(sa[0])
while len(sa)!=0 or len(sb)!=0 or len(sc)!=0:
    #print(sa,sb,sc)
    if cnt=='a':
        cnt=sa[0]
        sa.remove(sa[0])
    elif cnt=='b':
        cnt=sb[0]
        sb.remove(sb[0])
    elif cnt=='c':
        cnt=sc[0]
        sc.remove(sc[0])
    if len(sa)==0 and cnt=='a':
        print("A")
        break
    elif len(sb)==0 and cnt=='b':
        print("B")
        break
    elif len(sc)==0 and cnt=='c':
        print("C")
        break
Problem p02801 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
a = str(input())
# 文字列の入力
 
# 出力
print(chr(ord(a) + 1))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
a = str(input())
# 文字列の入力

# 出力
print chr(ord(a) + 1)
Problem p03636 (python)

Fixed submission:
s = input()
# 頭とお尻の文字数を引く
n = len(s) - 2
# 頭とお尻をくっつくて出力
print(s[0] + str(n) + s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
# 頭とお尻の文字数を引く
n = len(s) - 2
# 頭とお尻をくっつくて出力
print(f'{s[0]}{n}{s[-1]}')
Problem p02993 (python)

Fixed submission:
lst_A = list(input())
 
ans = "Bad"
 
for i in range(3):
	if lst_A[i] == lst_A[i + 1]:
  		break
else:
  ans = "Good"
  
print(ans)

Buggy submission (verdict: Runtime Error):

lst_A = list(input())

ans = "Bad"

for i in range(3):
	if lst_A[i] == lst_A[i + 1]
  		break
else:
  ans = "Good"
  
print(ans)
Problem p02995 (python)

Fixed submission:

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

Cw = C
Dw = D

if Cw < Dw:
    Cw, Dw = Dw, Cw
while Cw % Dw != 0:
    Cw, Dw = Dw, Cw % Dw

E = C * D // Dw

A -= 1

ans = (B - B // C - B // D + B // E) - (A - A // C - A // D + A // E)

print(ans)

Buggy submission (verdict: Runtime Error):

import math

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

A -= 1

E = (C * D) // math.gcd(C, D)

ans = (B - B // C - B // D + B // E) - (A - A // C - A // D + A // E)

print(ans)

Buggy submission (verdict: Runtime Error):

import math

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

A -= 1

E = (C * D) // math.gcd(C, D)

ans = (B - B // C - B // D + B // E) - (A - A // C - A // D + A // E)

print(ans)
Problem p02999 (python)

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

if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):

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

if X < A:
  print(0)
else:
  print(10)
Problem p03261 (python)

Fixed submission:

N = int(input())

lst_W = []
for i in range(N):
    lst_W.extend(input().split())

ans = "Yes"

for i in range(N - 1):
    if (lst_W[i])[-1:] != (lst_W[i+1])[:1]:
        ans = "No"
        break

if len(lst_W) != len(set(lst_W)):
    ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):

N = int(input())

lst_W = []
for i in range(N):
    lst_W.extend(input().split())

ans = "Yes"

for i in range(N - 1):
    if (lst_W[i])[-1:] != (lst_W[i+1])[:1]:
        ans = "No"
        break

if len(lst_W) != len(set(lst_W)):
    #ans = "No"

print(ans)
Problem p02658 (python)

Fixed submission:
import sys

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

if(0 in A):
    print(0)
    sys.exit(0)

prod = 1
for a in A:
    prod *= a
    if prod > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(prod)

Buggy submission (verdict: Runtime Error):
import sys

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

if(A.index(0) >= 0):
    print(0)
    sys.exit(0)

prod = 1
for a in A:
    prod *= a
    if prod > 1000000000000000000:
        print(-1)
        sys.exit(0)

print(prod)
Problem p02780 (python)

Fixed submission:
from itertools import accumulate

n, k = map(int, input().split())
p = list(map(int, input().split()))

st = list(accumulate(range(1001)))
#print(st)
table = [0] * (n + 1)
for i in range(1, len(table)):
    table[i] = table[i-1] + (st[p[i-1]] / p[i-1])
    #print(i, p[i-1], st[p[i-1]], table[i])
    
ans = table[k]
for i in range(k+1, len(table)):
    ans = max(ans, table[i] - table[i-k])

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))

p_max = max(p)

l_range = list(range(1001))
st = [sum(l_range[:i]) for i in range(1001)][1:]
#print(st)
table = [0] * (n + 1)
for i in range(1, len(table)):
    table[i] = table[i-1] + (st[p[i-1]] / p[i-1])
    #print(i, p[i-1], st[p[i-1]], table[i])
    
ans = table[k]
for i in range(k+1, len(table)):
    ans = max(ans, table[i] - table[i-k])

print(ans)
Problem p03284 (python)

Fixed submission:
a = input()
num = a.split(' ')
N = int(num[0])
K = int(num[1])
j = N % K
if j == 0:
	print(0)
else:
	print(1)

Buggy submission (verdict: Runtime Error):
a = input()
num = a.split(' ')
N = num[0]
K = num[1]
j = N % K

if j == 0:
	print(0)
else:
	print(1)
Problem p03288 (python)

Fixed submission:
rate = int(input())

if rate >= 0 and rate <= 1199:
	print('ABC')
elif rate >= 1200 and rate <= 2799:
	print('ARC')
else:
	print('AGC')

Buggy submission (verdict: Runtime Error):
rate = int(input())

if rate >= 0 && rate <= 1199:
	print('ABC')
elif rate >= 1200 && rate <= 2799:
	print('ARC')
else:
	print('AGC')
Problem p03997 (python)

Fixed submission:
a = [int(input()) for i in range(3)]
print(int((a[0]+a[1])*a[2]/2))

Buggy submission (verdict: Runtime Error):
a = [int(input()) for i in range(5)]
(a[0]+a[1])*a[2]/2
Problem p02865 (python)

Fixed submission:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    if N == 1 or N == 2:
        print(0)
        return

    print((N-1)//2)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    ans = 0.0

    for i in range(1, N+1):
        c = 0
        if i < K:
            c = math.ceil(math.log2(K) - math.log2(i))
        # print(i, c, (1.0 / (2 ** c)), 1.0/N)
        ans += (1.0 / (2 ** c)) * 1.0/N

    print("{0:.20f}".format(ans))


if __name__ == '__main__':
    main()
Problem p02866 (python)

Fixed submission:
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    N = int(input())
    d = list(map(int, input().split()))

    distance = [0] * (N + 1)

    for _d in d:
        distance[_d] += 1

    if d[0] != 0 or distance[0] != 1:
        print(0)
        return

    ans = 1
    for i in range(1, (N + 1)):
        n = distance[i-1]
        r = distance[i]
        ans = ans * n ** r
        ans = ans % MOD
        # print(ans)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for d in D:
        distance[d[0]] += 1

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            c = cmb(n+r-1, r-1, MOD)
            # print('n', n, 'r', r, 'c', c)
            ans *= n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()
Problem p02936 (python)

Fixed submission:
import sys
import queue
input = sys.stdin.readline
N, Q = map(int, input().split())
 
tree = [[] for i in range(N+1)]
values = [0] * (N+1)
visit = [False]*(N+1)
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x
 
 
q = queue.Queue()
q.put(1)
visit[1] = True
while (not q.empty()):
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            values[next] += values[now]
            visit[next] = True
            q.put(next)
 
values = values[1:]
print(" ".join(map(str, values)))

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = list(map(int, input().split()))
    parents = {}
    ans = [0] * N

    for i in range(N-1):
        a, b = list(map(int, input().split()))
        parents[b-1] = a - 1

    for i in range(Q):
        p, x = list(map(int, input().split()))
        ans[p-1] += x

    for i in range(1, N):
        ans[i] += ans[parents[i]]

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


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = list(map(int, input().split()))
    nodes = [None] * N
    ans = [0] * N

    for i in range(N-1):
        a, b = list(map(int, input().split()))

        if nodes[a-1] is None:
            nodes[a-1] = []

        nodes[a-1].append(b-1)

    # print()
    # print(nodes)

    for i in range(Q):
        p, x = list(map(int, input().split()))
        li = nodes[p-1]

        ans[p-1] += x

        if li is None:
            continue

        queue = li.copy()
        while len(queue) != 0:
            # print(queue)
            n = queue.pop(0)
            ans[n] += x

            if nodes[n] is not None:
                for next_n in nodes[n]:
                    queue.append(next_n)
        # print(i, ans)

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


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N, Q = list(map(int, input().split()))
p = [0] * Q
x = [0] * Q
nodes = [None] * N
ans = [0] * N

for i in range(N-1):
    a, b = list(map(int, input().split()))

    if nodes[a-1] is None:
         nodes[a-1] = []

    nodes[a-1].append(b-1)

# print()
# print(nodes)

for i in range(Q):
    p, x = list(map(int, input().split()))
    li = nodes[p-1]

    ans[p-1] += x

    if li is None:
        continue

    queue = li.copy()
    while len(queue) != 0:
        n = queue.pop(0)
        ans[n] += x

        if nodes[n] is not None:
            for next_n in nodes[n]:
                queue.append(next_n)

    # print(i, ans)

print(' '.join(map(str, ans)))
Problem p02937 (python)

Fixed submission:

# import sys
# input = sys.stdin.readline
import bisect


def ch_to_int(c):
    return ord(c) - 96


def main():
    s = input()
    t = input()
    pos = 0
    count = 0
    ch = [[] for i in range(27)]

    for i in range(len(s)):
        ch[ch_to_int(s[i])].append(i)

    for i in range(len(t)):
        c = ch_to_int(t[i])
        li = ch[c]

        if len(li) == 0:
            pos = -1
            count = 0
            break

        next_index = bisect.bisect_left(li, pos)
        # print(next_index, pos, li)
        if next_index >= len(li):
            next_pos = li[0]
            count += 1
            pos = next_pos + 1
        else:
            if pos == li[next_index]:
                pos += 1
            else:
                pos = li[next_index] + 1
        # print(li, next_index, pos, count)

    print(pos + count * len(s))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

# import sys
# input = sys.stdin.readline
import bisect


def ch_to_int(c):
    return ord(c) - 96


def main():
    s = input()
    t = input()
    pos = 0
    count = 0
    ch = [[] for i in range(26)]

    for i in range(len(s)):
        ch[ch_to_int(s[i])].append(i)

    for i in range(len(t)):
        c = ch_to_int(t[i])
        li = ch[c]

        if len(li) == 0:
            pos = -2
            count = 0
            break

        next_index = bisect.bisect_right(li, pos)
        if next_index >= len(li):
            next_pos = li[0]
            count += 1
            pos = next_pos
        else:
            pos = li[next_index]

    print((pos + 1) + count * len(s))


if __name__ == '__main__':
    main()
Problem p02960 (python)

Fixed submission:
MOD = 10**9 + 7

S = input()
L = len(S)
memo = [[0 for i in range(14)] for j in range(L + 1)]
dp = [[0 for i in range(14)] for j in range(L + 1)]

dp[0][0] = 1

for k in range(L):
    for m in range(13):
        if S[k] == '?':
            for i in range(10):
                dp[k + 1][(m * 10 + i) % 13] += dp[k][m]
        else:
            dp[k + 1][(m * 10 + int(S[k])) % 13] += dp[k][m]

        for i in range(13):
            dp[k+1][i] %= MOD

print(dp[L][5])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
memo = None


def rec(S, k, total):
    if k == len(S)//3:
        # print(total)
        fixed_total = total + 5 if k % 2 == 0 else total - 5
        memo[k][total % 13] = int((fixed_total) % 13 == 0)
        return int((fixed_total) % 13 == 0)

    if memo[k][total % 13] is not None:
        return memo[k][total % 13]

    s = S[k*3:k*3+3]
    d1 = [str(i) for i in range(10)] if s[0] == '?' else [s[0]]
    d2 = [str(i) for i in range(10)] if s[1] == '?' else [s[1]]
    d3 = [str(i) for i in range(10)] if s[2] == '?' else [s[2]]
    ret = 0

    for i1 in d1:
        for i2 in d2:
            for i3 in d3:
                num = int(i1 + i2 + i3)
                if k % 2 == 0:
                    ret += rec(S, k+1, total + num)
                else:
                    ret += rec(S, k+1, total - num)

    memo[k][total % 13] = ret
    return ret

S = input()

if len(S) % 3 == 1:
    S = '00' + S
elif len(S) % 3 == 2:
    S = '0' + S

L = (len(S) // 3) + 1
memo = [[None for i in range(14)] for j in range(L)]
print(rec(S, 0, 0) % MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
memo = None


def rec(S, k, total):
    if k == len(S)//3:
        # print(total)
        fixed_total = total + 5 if k % 2 == 0 else total - 5
        memo[k][total % 13] = int((fixed_total) % 13 == 0)
        return int((fixed_total) % 13 == 0)

    if memo[k][total % 13] is not None:
        return memo[k][total % 13]

    s = S[k*3:k*3+3]
    d1 = [str(i) for i in range(10)] if s[0] == '?' else [s[0]]
    d2 = [str(i) for i in range(10)] if s[1] == '?' else [s[1]]
    d3 = [str(i) for i in range(10)] if s[2] == '?' else [s[2]]
    ret = 0

    for i1 in d1:
        for i2 in d2:
            for i3 in d3:
                num = int(i1 + i2 + i3)
                if k % 2 == 0:
                    ret += rec(S, k+1, total + num)
                    ret %= MOD
                else:
                    ret += rec(S, k+1, total - num)
                    ret %= MOD

    memo[k][total % 13] = ret
    return ret

S = input()

if len(S) % 3 == 1:
    S = '00' + S
elif len(S) % 3 == 2:
    S = '0' + S

L = (len(S) // 3) + 1
memo = [[None for i in range(13)] for j in range(L)]
print(rec(S, 0, 0))
Problem p03029 (python)

Fixed submission:
A, P = map(int, input().split())
 
print((A * 3 + P) // 2)

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

print((A * 3 + p) // 2)