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

Fixed submission:
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()
tugi = [0]+a
town  =1
route = [0]*n
route[0] = town
used = [False]*n
used[0] = True
for i in range(n):
    town = tugi[town]
    if used[town-1]:
        i = route.index(town)
        notcycle = route[:i]
        cycle = route[i:]
        break
    used[town-1] = True
    route[i+1] = town

for i in range(n):
    if cycle[i] == 0:
        cycle = cycle[:i]
        break

if len(notcycle) >k:
    print(notcycle[k])
else:
    k -= len(notcycle)
    print(cycle[k%len(cycle)])

Buggy submission (verdict: Runtime Error):
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()
tugi = [0]+a
cyclestart = []
town  =1
temp = [town, ]

while True:
    town = tugi[town]
    if town in temp:
        i = temp.index(town)
        notcycle = temp[:i]
        cycle = temp[i:]
        cyclestart.append(town)
        break
    temp.append(town)
k -= len(notcycle)
print(cycle[k%len(cycle)])
Problem p02865 (python)

Fixed submission:
n = int(input())
if n%2 == 0:
    print((n-2)//2)
else:
    print((n-1)//2)

Buggy submission (verdict: Runtime Error):
n = INT()
if n%2 == 0:
    print((n-2)//2)
else:
    print((n-1)//2)
Problem p02898 (python)

Fixed submission:
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, k = MAP()
h = LIST()
count = 0
for i in h:
    if i >= k:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, k = INT()
h = LIST()
count = 0
for i in h:
    if i >= k:
        count += 1
print(count)
Problem p02900 (python)

Fixed submission:
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a, b = MAP()
gcd = fractions.gcd(a,b)

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

prime = prime_factorize(gcd)
print(len(set(prime))+1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a, b = MAP()
gcd = math.gcd(a,b)

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

prime = prime_factorize(gcd)
print(len(set(prime))+1)
Problem p02924 (python)

Fixed submission:
n = int(input())
print((n*(n-1))//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
print((n(n-1))//2)
Problem p02934 (python)

Fixed submission:
from fractions import Fraction
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i] = Fraction(1, a[i])

print(float(Fraction(1,sum(a))))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

def cal(a):
  return 1/a

aa = cal(a)
aa_sum = sum(aa)

print(cal(aa_sum))
Problem p02953 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
count = True
for i in range(n-1):
  if h[i+1]-h[i] < -1:
    count = False
    break
  elif h[i+1]-h[i] == -1:
    h[i+1] += 1
if count == True:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [0]*n
for i in range(n):
  h[i] = int(input())
count = True
for i in range(n-1):
  if h[i+1]-h[i] < -1:
    count = False
    break
  elif h[i+1]-h[i] = -1:
    h[i+1] += 1
if count == True:
  print("Yes")
else:
  print("No")
Problem p02971 (python)

Fixed submission:
import numpy as np
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
    
b = np.array(a)
b = np.sort(b)[::-1]

ans = [0]*n

for i in range(n):
    if a[i] == b[0]:
        ans[i] = b[1]
    else:
        ans[i] = b[0]
        
for i in range(n):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
n= int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
b = a
max = max(a)
for i in range(n):
    if a[i] == max:
        a[i] = 0
        print(max(a))
        a[i] = max
        
    else:
        print(max)
Problem p02981 (python)

Fixed submission:
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

a,b,c = MAP()
print(min(a*b,c))

Buggy submission (verdict: Runtime Error):
a,b,c = int(input())
print(min(a*b,c))

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
import numpy as np
LL = L%2019
RR = R%2019
min = 2019


for i in range(LL, RR+1):
    for j in range(i+1, RR+1):
        if (i*j)%2019 < min:
            min= (i*j)%2019

        if (i*j)%2019 == 0:
            min = 0
            break
    else:
        continue
    break
        

print(min)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
import numpy as np
LL = L%2019
RR = R%2019
min = 2019


for i in range(LL, RR+1):
  for j in range(i+1, RR+1):
    if (i*j)%2019 == 0:
      min = 0
      break
    elif (i*j)%2019 < min:
      min= (i*j)%2019


print(min)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
import numpy as np
min = 2019
for i in range(L, R+1):
    for j in range(i+1, R+1):
        if (i*j)%2019 < min:
            min = (i*j)%2019

print(min)
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())
import numpy as np
LL = L%2019
RR = R%2019

min = 2019
if LL >= RR:
    min = 0
elif R-L >= 2018:
    min = 0
else:
    for i in range(LL, RR+1):
        for j in range(i+1, RR+1):
            if (i*j)%2019 < min:
                min = (i*j)%2019
            if (i*j)%2019 == 0:
                min = 0
                break
        else:
            continue
        break


print(min)

Buggy submission (verdict: Runtime Error):
L, R = map(int, input().split())
import numpy as np
LL = L%2019
RR = R%2019
min = 2019


for i in range(LL, RR+1):
	for j in range(i+1, RR+1):
    	if (i*j)%2019 == 0:
        	min = 0
        	break
        elif (i*j)%2019 < min:
            min= (i*j)%2019


print(min)
Problem p03061 (python)

Fixed submission:
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

L = [0]*n
R = [0]*n
L[0] = INF
L[1] = a[0] 
R[n-1] = INF
R[n-2] = a[n-1]

GCDs = [0]*n

for i in range(2, n):
    L[i] = fractions.gcd(L[i-1], a[i-1])

for i in range(n-3,-1,-1):
    R[i] = fractions.gcd(R[i+1], a[i+1])

GCDs[0] = R[0]
GCDs[n-1] = L[n-1]

for i in range(1,n-1):
    GCDs[i] = fractions.gcd(L[i], R[i])

res = max(GCDs)

print(res)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

res = 0
for i in range(n):
    aa = a[:i] + a[i+1:]
    gcd = reduce(math.gcd, aa)
    res = max(res,gcd)

print(res)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
import functools
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

res = 0
for i in range(n):
    aa = a[:i] + a[i+1:]
    gcd = functools.reduce(math.gcd, aa)
    res = max(res,gcd)

print(res)
Problem p03565 (python)

Fixed submission:
ss = input()
tt = input()
ans = ''
for i in range(len(ss)-len(tt)+1):
    flag = True
    for s,t in zip(ss[i:],tt):
        if s != '?' and s != t:
            flag = False
            break
    if flag:
        ans = ss[:i] + tt + ss[i+len(tt):]

if ans !='':
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
ss = input()
t = insput()

def search(ss,t):
    ans = []
    if len(ss) < len(t):
        return ans
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss_ans = ss.replace(ss[i:len(t)+i], t)
            while '?' in ss_ans:
                ss_ans = ss_ans.replace('?', 'a')
            ans.append(ss_ans)
    return ans

if len(search(ss, t)) == 0:
    print('UNRESTORABLE')
else:
    ans_list = sorted(search(ss, t))
    print(ans_list)
    s = ans_list[0]
    print(s)
Problem p03633 (python)

Fixed submission:
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
t = [0]*n
for i in range(n):
    t[i] = INT()

def lcm(a,b):
    gcd = fractions.gcd(a,b)
    a//=gcd
    b//=gcd
    return a*b*gcd
    
if n == 1:
    print(t[0])
    sys.exit()

res = lcm(t[0],t[1])
for i in range(1,n-1):
    res = lcm(res, t[i+1])

print(res)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
t = [0]*n
for i in range(n):
    t[i] = INT()

def lcm(a,b):
    gcd = fractions.gcd(a,b)
    a//=gcd
    b//=gcd
    return a*b*gcd
res = lcm(t[0],t[1])
for i in range(1,n-1):
    res = lcm(res, t[i+1])

print(res)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
t = [0]*n
for i in range(n):
    t[i] = INT()

def lcm(a,b):
    gcd = fractions.gcd(a,b)
    a//=gcd
    b//=gcd
    return a*b*gcd

for i in range(n-1):
    res = lcm(t[i], t[i+1])
    
print(res)
Problem p03722 (python)

Fixed submission:
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n,m = MAP()
E = [[(0,0,0)]for i in range(m)]
for i in range(m):
    a,b,cost = MAP()
    E[i] = (a-1, b-1, -1*cost)

d = [INF]*n
d[0] = 0
for i in range(n-1):
    for e in E:
        if d[e[0]] != INF and d[e[0]]+e[2] < d[e[1]]:
            d[e[1]] = d[e[0]]+e[2]
res =  d[n-1]

for e in E:
    if d[e[0]] != INF and d[e[0]]+e[2] < d[e[1]]:
            d[e[1]] = d[e[0]]+e[2]




if  res != d[n-1]:
    print('inf')
else:
    print(res*-1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n,m = MAP()
E = [[(0,0,0)]for i in range(m)]
for i in range(m):
    a,b,cost = MAP()
    E[i] = (a-1, b-1, -1*cost)



def bellmanford(s, E): #無向グラフの時はEに双方向から辺を追加
    d = [INF]*n
    d[s] = 0
    for i in range(n-1):
        for e in E:
            if d[e[0]] != INF and d[e[0]]+e[2] < d[e[1]]:
                d[e[1]] = d[e[0]]+e[2]
    return d

def find_negative_loop(s,E):
    d = bellmanford(s, E)
    negative = [False]*n
    for i in range(n):
        for j in range(m):
            if d[E[j][0]] != INF and d[E[j][0]]+E[j][2] < d[E[j][1]]:
                d[E[j][1]] = d[E[j][0]]+E[j][2]
                negative[j] = True
            if negative[E[j][0]]:
                negative[E[j][1]] = True

    return negative[n-1]

res = bellmanford(0,E)
if find_negative_loop(0,E):
    print('inf')
else:
    print(res[n-1]*-1)
Problem p03035 (python)

Fixed submission:
a,b=map(int,input().split())

if a<6:
    print("0")
elif a<13:
    print(int(b/2))
else:
    print(b)

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

n,m=map(int,input().split())
a=input().split()
a = list(map(int, a))
a = np.array(a)
for i in range(m):
    a = np.sort(a)
    b,c=map(int,input().split())
    for j in range(b):
        if a[j]<c:
            a[j] = c
a = np.array(a)
print(a.sum())
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 % ==0):
  print("Even")
else:
  print("Odd")
Problem p03493 (python)

Fixed submission:
a = input()
a = int(a)
if a==111:
  print("3")
elif a==101 or a==110 or a==11:
  print("2")
elif a ==0:
  print("0")
else:
  print("1")

Buggy submission (verdict: Runtime Error):
    a = input()
    if a == 111:
      print("3")
    elif a == 101 or a==110 or a== 11:
      print("2")
    elif a = 0:
      print("0")
    else:
      print("1")

Buggy submission (verdict: Runtime Error):
a = input()
if a == 111:
  print("3")
elif a == 101 | a==110 | a== 11:
  print("2")
elif a = 0:
  print("0")
else:
  print("1")
Problem p02698 (python)

Fixed submission:
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

N = int(input())

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

F = [-1 for _ in range(N)]
F[0] = 1
INF = 10 ** 9
dp = [INF for _ in range(N + 1)]
dp[0] = A[0]


def dfs(s):
    for d in T[s]:
        if F[d] == -1:
            t = bisect.bisect_left(dp, A[d])
            p = dp[t]
            dp[t] = A[d]
            F[d] = bisect.bisect_left(dp, INF)
            dfs(d)
            dp[t] = p


dfs(0)

print("\n".join(map(str, F)))

Buggy submission (verdict: Runtime Error):
import bisect

N = int(input())

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

F = [[] for _ in range(N)]


def dfs(s):
    for d in T[s]:
        if not F[d]:
            F[d] = F[s][:]
            t = bisect.bisect_left(F[d], A[d])
            if t == len(F[d]):
                F[d].append(A[d])
            else:
                F[d][t] = A[d]
            dfs(d)


F[0] = [A[0]]
dfs(0)

for f in F:
    print(len(f))
Problem p02804 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
res = 0
mod = 10**9+7

fac = [1]
caf = [1]


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


for i in range(1, n+1):
    fac.append((fac[i - 1] * i) % mod)
    caf.append(pow(fac[i], mod - 2))


def ncr(n, r):
    if n < r or r < 0:
        return 0
    return fac[n] * caf[r] * caf[n - r]



res = 0
for i in range(n):
    res += (a[i]*ncr(i,k-1))%mod
    res -= (a[i]*ncr(n-i-1,k-1))%mod
    res %= mod

print(res)

Buggy submission (verdict: Runtime Error):
import collections
h,w = map(int, input().split())
s=[input()for _ in range(h)]

r=[[1,0],[-1,0],[0,1],[0,-1]]
def bfs(i,j):
    global h,w,r
    f=[-1 for _ in range(h*w)]
    que = collections.deque([[i,j,0]])
    while que:
        i,j,k = que.popleft()
        f[i*w+j] =k
        for sr in r:
            ti = i + sr[0]
            tj = j + sr[1]
            if ti>=0 and tj>=0 and ti<h and tj<w:
                if s[ti][tj] == ".":
                    if f[ti*w+tj] == -1:
                        que.append([ti,tj,k+1])
    return max(f)


res = 0
for i in range(h):
    for j in range(w):
        if s[i][j] ==".":
            tres = bfs(i,j)
            res = max(res,tres)
print(res)
Problem p02813 (python)

Fixed submission:
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
perms = []
for i in itertools.permutations([j+1 for j in range(n)]):
    perms.append(list(i))
perms.sort()
for i in range(len(perms)):
    if perms[i]==p:
        rp = i
    if perms[i] ==q:
        rq = i
print(abs(rq-rp))

Buggy submission (verdict: Runtime Error):
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
perms = []
for i in itertools.permutations([j+1 for j in range(n)]):
    perms.append(list(i))
perms.sort()
for i in range(len(perms)):
    if perms[i]==p:
        rp = i
    elif perms[i] ==q:
        rq = i
print(abs(rq-rp))
Problem p02899 (python)

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

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))

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

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

res = str(l[0][1])
for i in range(1, n):
    res = res + " " + str(l[0][i])
print(res)
Problem p02923 (python)

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

result = 0
tempres = 0
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        continue
    for j in range(i, N - 1):
        if H[j] >= H[j + 1]:
            tempres += 1
        else:
            break
    result = max(result, tempres)
    if result >= N - i - 1:
        break
print(result)

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

result = 0
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        break
    for j in range(i, N - 1):
        if H[j] >= H[j + 1]:
            tempres += 1
        else:
            break
    result = max(result, tempres)
    if result >= N - i - 1:
        break
print(result)

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

result = 0
for i in range(0, N)
    if maxi != 0:
        maxi -= 1
        break
    for j in range(i, N - 1):
        if H[j] >= H[j + 1]:
            tempres += 1
        else:
            break
    result = max(result, tempres)
    maxi = i
    if result >= N - i - 1:
        break
print(result)
Problem p02960 (python)

Fixed submission:
def main():
    sts=input()
    n= len(sts)
    mod = 10**9+7
    s = []
    for c in sts:
        s.append(c)

    dp = [[0 for _ in range(13)]for _ in range(n)]

    ss = s[0]
    if ss == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        ss = int(ss)
        dp[0][ss] = 1

    for i in range(1,n):
        ss = s[i]
        if ss == "?":
            for k in range(10):
                for j in range(13):
                    dp[i][(j * 10 +k) % 13] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][(j * 10 +int(ss)) % 13] += dp[i-1][j]
        for j in range(13):
            dp[i][j]%= mod


    print(dp[n-1][5])

main()

Buggy submission (verdict: Runtime Error):
def main():
    sts=input()
    n= len(sts)
    mod = 10**9+7
    s = []
    for c in sts:
        s.append(c)

    dp = [[0 for _ in range(13)]for _ in range(n)]

    ss = s[0]
    if ss == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        ss = int(ss)
        dp[0][ss] = 1

    for i in range(1,n):
        ss = s[i]
        if ss == "?":
            for k in range(10):
                for j in range(13):
                    dp[i][(j * 10 +k) % 13] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][(j * 10 +int(ss)) % 13] += dp[i-1][j]
        for j in range(13):
            dp[j][i]= mod


    print(dp[n-1][5])

main()
Problem p02995 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
cd = lcm(c,d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
cd = c * d / math.gcd(c, d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))