Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, input().split())
    price = [0]*m
    typesnum = [0]*m
    types = [[] for _ in range(m)]
    for i in range(m):
        price[i], typesnum[i] = map(int, input().split())
        types[i] = list(map(lambda x: int(x)-1, input().split()))
    dp = [10**9]*(1 << n)
    dp[0]=0
    for bit in range(1 << n):
        for i in range(m):
            keybit = 0
            for op in types[i]:
                keybit |= 1 << op
            dp[bit | keybit] = min(dp[bit | keybit], dp[bit]+price[i])
    if dp[-1] == 10**9:
        dp[-1] = -1
    print(dp[-1])


if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, input().split())
    price = [0]*m
    typesnum = [0]*m
    types = [[] for _ in range(m)]
    for i in range(m):
        price[i], typesnum[i] = map(int, input().split())
        types[i] = list(map(lambda x: int(x)-1, input().split()))
    dp = [10**9]*(1 << n)
    dp[0]=0
    for bit in range(1 << n):
        for i in range(m):
            keybit = 0
            for op in types[i]:
                keybit |= 1 << op
            dp[bit | keybit] = min(dp[bit | keybit], dp[bit]+price[i])
    if dp[-1] == 10**9:
        dp[-1] = -1
    print(dp[-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from collections import defaultdict
def input(): return sys.stdin.readline().rstrip()


def main():
    mod = 10**9+7
    S = input()[::-1]
    amari = 1
    dp = np.zeros((len(S), 13),dtype='int64')
    if S[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(S[0])] = 1

    for i in range(1, len(S)):
        amari = 10*amari % 13
        if S[i] == '?':
            for j in range(13):
                for si in range(10):
                    dp[i][(j+amari*si) % 13] += dp[i-1][j]
                    dp[i][(j+amari*si) % 13] %= mod

        else:
            for j in range(13):
                dp[i][(j+amari*int(S[i])) % 13] = dp[i-1][j]
    
    print(dp[len(S)-1][5])


if __name__ == '__main__':
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    mod = 10**9+7
    S = input()[::-1]
    amari = 1
    dp = [[0]*13 for i in range(len(S))]
    if S[0] == '?':
        for j in range(10):
            dp[0][j] = 1
    else:
        dp[0][int(S[0])] = 1

    for i in range(1, len(S)):
        amari = 10*amari % 13
        if S[i] == '?':
            for j in range(13):
                for si in range(10):
                    dp[i][(j+amari*si) % 13] += dp[i-1][j]
                    dp[i][(j+amari*si) % 13] %= mod

        else:
            for j in range(13):
                dp[i][(j+amari*int(S[i])) % 13] = dp[i-1][j]

    print(dp[len(S)-1][5])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
, X, T = map(int,input().split())
n = 0
total = 0

if N % X == 0:
    n = N / X
    total = n * T
else:
    n = N // X + 1
    total = n * T

print(int(total))

Fixed submission:
N, X, T = map(int,input().split())
n = 0

if N % X == 0:
    n = N / X
else:
    n = N // X + 1

print(int(n * T))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
count = 0
K = True

while K:
    for i in range(N):
        if A[i] % 2 ==1:
            K = False
        A[i] / 2

    if not K:
            break
    count += 1

print(count)

Fixed submission:
s1s2s3 = input()

print(s1s2s3.count('1'))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
A = [int(a) for a in input().split(" ")]

firstgcds = [0]
lastgcds = [0]
for i in range(0, N):
    firstgcds.append(math.gcd(firstgcds[i], A[i]))
    lastgcds.append(math.gcd(lastgcds[i], A[-i-1]))
ans = 0
for i in range(0, N):
    preans = math.gcd(firstgcds[i], lastgcds[-i-2])
    if ans < preans:
        ans = preans
if ans < firstgcds[N-1]:
    ans = firstgcds[N-1]
print(ans)


Fixed submission:
import fractions

N = int(input())
A = [int(a) for a in input().split(" ")]

firstgcds = [0]
lastgcds = [0]
for i in range(0, N):
    firstgcds.append(fractions.gcd(firstgcds[i], A[i]))
    lastgcds.append(fractions.gcd(lastgcds[i], A[-i-1]))
ans = 0
for i in range(0, N):
    preans = fractions.gcd(firstgcds[i], lastgcds[-i-2])
    if ans < preans:
        ans = preans
if ans < firstgcds[N-1]:
    ans = firstgcds[N-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)

max = X[0] * Y[0]

for i in range(1, len(X)):
	for j in range(1, len(Y)):
		if max < X[i] * Y[j]:
			max = X[i] * Y[j]
print(max)

Fixed submission:
a,b,c,d = map(int, input().split())
list = [a*c, a*d, b*c, b*d]
print(max(list))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)

max = X[0] * Y[0]

for i in range(1, len(X)):
	for j in range(1, len(Y)):
		if max < X[i] * Y[j]:
			max = X[i] * Y[j]
print(max)


Fixed submission:
a,b,c,d = map(int, input().split())
list = [a*c, a*d, b*c, b*d]
print(max(list))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

x = range(a,b+1)
y = range(c,d+1)

X = list(x)
Y = list(y)
MAX = max(X) * max(Y)
print(MAX)

Fixed submission:
a,b,c,d = map(int, input().split())
list = [a*c, a*d, b*c, b*d]
print(max(list))
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = (N%100)%10
if X == 3:
  print('bon')
elif X == 0 or X = 1 or X == 6 or X = 8:
  print('pon')
else:
  print('hon')

Fixed submission:
N = int(input())
X = (N%100)%10
if X == 3:
  print('bon')
elif X == 0 or X == 1 or X == 6 or X == 8:
  print('pon')
else:
  print('hon')
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

print(if S == T[:-1]'Yes' else 'No')

Fixed submission:
S = input()
T = input()
if S == T[:-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = input()
print('Yes' if 7 in N else 'No')


Fixed submission:
N = input()
print('Yes' if '7' in N else 'No')
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = a*c
	if c>=0:
		answer = a * c
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			elif:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)


Fixed submission:
a,b,c,d = map(int,input().split())
answer =0
if b < 0:
	if c < 0:
		answer = max(a*c,b*d)
	if c>=0:
		answer = max(a*c,b*d,b*c)
if b>=0:
	if a <0:
		answer = max(a*c ,b * d,0)
	if a >= 0:
		if d< 0:
			if a == 0:
				answer = 0
			else:
				answer = a*d
		if d>=0:
			answer = b*d
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def get_distance(x1, y1, x2, y2):
	d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
	return d
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N, D  = map(int, input().split())
count = 0
num_list = []
for i in range(N):
    num_list.append(list(map(int,input().split())))
get_unique_list(num_list)

for i in range (N):
	k = get_distance(num_list[i][0], num_list[i][1], 0, 0)
	if k <= D:
		count += 1

print(count)

Fixed submission:
import math

def get_distance(x1, y1):
	d = math.sqrt((x1) ** 2 + (y1) ** 2)
	return d


N, D  = map(int, input().split())
count = 0
num_list = []
for i in range(N):
    num_list.append(list(map(int,input().split())))


for i in range (N):
	if abs(num_list[i][0]<= D) and abs(num_list[i][1]) <= D:
		
		k = get_distance(num_list[i][0], num_list[i][1])
		if k <= D:
			count += 1


print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N = int(input())
a = 0
for i in range (N):
	a = a + (i+1)*len(make_divisors(i+1))
print(a)

Fixed submission:
N = int(input())
a = 0
for i in range (N):
	x= N//(i+1)
	a += x*(x+1)*(i+1)

a = a/2
	
print(int(a))
Buggy python submission (verdict: Runtime Error):
N = int(input())

s = []
k = 0
while N > 0:
	l = N % 26 //一番下のけた
	s.insert(0,chr(ord('a')+l-1))
	N = N // 26
	k +=1

print(s)
print(join(s))

Fixed submission:
N = int(input())

s = []
k = 0
while N > 0:
	l = N % 26 #一番下のけた
	if l == 0:
		l = 26
	s.insert(0,chr(ord('a')+l-1))
	N = N-1
	N = N // 26
	k +=1


print(''.join(s))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
b = a
c= a[1]^a[2]
S = 0
for i in range(N):
	S = S^a[i]

for i in range(N):
	b[i] = S^a[i]

print(*b)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
b = a
S = 0
for i in range(N):
	S = S^a[i]

for i in range(N):
	b[i] = S^a[i]

print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
total = 1
for i in range(len(a)):
	total *= a[i]
if total > 10**18:
	total =-1
    
print(total)

Fixed submission:
N = int(input())
a = list(map(int,input().split()))
total = 1
k = 10**18
for i in range(len(a)):
	if a[i] == 0:
		total = 0
		break
if total != 0:
  for i in range(len(a)):	
      total *= a[i]
      if total > k:
          total =-1
          break    
print(total)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A,B =list(map(int,input().split()))
count =0
while count * K<A:
	count +=1
if count *K <=B:
	print("OK")
else
	print("NG")

Fixed submission:
K = int(input())
A,B =list(map(int,input().split()))
count =0
while count * K<A:
	count +=1
if count *K <=B:
	print("OK")
else:
	print("NG")
Buggy python submission (verdict: Runtime Error):
A,B,C,D = list(map(int,input().split()))

while 1:
	C -= B
	if C<=0
		print("Yes")
		break
	A -= D 
	if A<=0
		print("No")
		break

Fixed submission:
A,B,C,D = list(map(int,input().split()))

while 1:
	C -= B
	if C<=0:
		print("Yes")
		break
	A -= D 
	if A<=0:
		print("No")
		break
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

H = list(map(int, input().split()))

ans = [str(i+1) for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        try:
            ans.remove(str(b))
        except Exception as e:
            continue
    elif H[b-1] > H[a-1]:
        try:
            ans.remove(str(a))
        except Exception as e:
            continue
    else:
        try:
            ans.remove(str(a))
            try:
                ans.remove(str(b))
            except Exception as e:
                continue
        except Exception as e:
            try:
                ans.remove(str(b))
            except Exception as e:
                continue

print(len(ans))

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

H = list(map(int, input().split()))

ans = {}

for _ in range(M):
    a, b = map(int, input().split())
    if H[a-1] > H[b-1]:
        ans[str(b)] = 1
    elif H[b-1] > H[a-1]:
        ans[str(a)] = 1
    else:
        ans[str(a)] = 1
        ans[str(b)] = 1

print(N - len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = input().split()

for i in range(n):
    print(a.count(str(i+1)))

Fixed submission:

n = int(input())

a = list(map(int, input().split()))

b = [0] * n

for i in range(n-1):
    b[a[i]-1] += 1

for i in range(n):
    print(b[i])
Buggy python submission (verdict: Time Limit Exceeded):

import sys

sys.setrecursionlimit(100000)

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)


k = int(input())

x = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        q = gcd(b, a)
        for c in range(1, k+1):
            x += gcd(q, c)

print(x)


Fixed submission:
from math import gcd


k = int(input())

ans = 0

gcd_sum = [0] * 201

for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i, j)

for a in range(1, k+1):
    for b in range(1, k+1):
        q = gcd(a, b)
        ans += gcd_sum[q]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


k = int(input())

x = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            x += gcd(a, b, c)

print(x)

Fixed submission:
from math import gcd


k = int(input())

ans = 0

gcd_sum = [0] * 201

for i in range(1, k+1):
    for j in range(1, k+1):
        gcd_sum[i] += gcd(i, j)

for a in range(1, k+1):
    for b in range(1, k+1):
        q = gcd(a, b)
        ans += gcd_sum[q]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

if n < abs(n-k):
    print(n)

else:
    while n > 0:
        n -= k
    print(min(abs(n), n+k))

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

print(min(n % k, k - n % k))
Buggy python submission (verdict: Runtime Error):
card = []

for _ in range(3):
    card.append(list(map(int, input().split())))

n = int(input())

b = []

for _ in range(n):
    b.append(int(input()))

for i in range(3):
    if card[i][0] in b and card[i][1] in b and card[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if card[0][i] in b and card[1][i] in b and card[2][i] in b:
        print('Yes')
        exit()
if card[0][0] and card[1][1] and card[2][2]:
    print('Yes')
    exit()
if card[0][2] and card[1][1] and card[2][0]:
    print('Yes')
    exit()


print('No')

Fixed submission:
import math

n = int(input())

n = math.ceil(n/2)

print(n)
Buggy python submission (verdict: Runtime Error):
N = input()
_list = input().split(" ")
_list = [int(a) for a in _list]
aspect = [a for a in _list if a % 2==0]
ans = []
for a in even:
    if a % 3 == 0 or a % 5 == 0:
        ans.append(True)
if len(aspect) ==len(ans):
    print("APPROVED")
else:
    print("DENIED")

Fixed submission:
N = input()
_list = input().split(" ")
_list = [int(a) for a in _list]
aspect = [a for a in _list if a % 2==0]
ans = []
for a in aspect:
    if a % 3 == 0 or a % 5 == 0:
        ans.append(True)
if len(aspect) ==len(ans):
    print("APPROVED")
else:
    print("DENIED")
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from collections import OrderedDict
n = int(input())
answer = dict()
for _ in range(n):
    z = str(input())
    if z in answer:
        ans[z]+=1
    else:
        answer.update({z:1})
groupedByValue = defaultdict(list)
for key, value in sorted(answer.items()):
    groupedByValue[value].append(key)
M = groupedByValue[max(groupedByValue)]
for i in M:
    print(i)

Fixed submission:
from collections import defaultdict
from collections import OrderedDict
n = int(input())
answer = dict()
for _ in range(n):
    z = str(input())
    if z in answer:
        answer[z]+=1
    else:
        answer.update({z:1})
groupedByValue = defaultdict(list)
for key, value in sorted(answer.items()):
    groupedByValue[value].append(key)
M = groupedByValue[max(groupedByValue)]
for i in M:
    print(i)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from collections import OrderedDict
n = int(input())
ans = dict()
for _ in range(n):
    z = str(input())
    if z in answer:
        ans[z]+=1
    else:
        answer.update({z:1})
groupedByValue = defaultdict(list)
for key, value in sorted(answer.items()):
    groupedByValue[value].append(key)
M = groupedByValue[max(groupedByValue)]
for i in M:
    print(i)

Fixed submission:
from collections import defaultdict
from collections import OrderedDict
n = int(input())
answer = dict()
for _ in range(n):
    z = str(input())
    if z in answer:
        answer[z]+=1
    else:
        answer.update({z:1})
groupedByValue = defaultdict(list)
for key, value in sorted(answer.items()):
    groupedByValue[value].append(key)
M = groupedByValue[max(groupedByValue)]
for i in M:
    print(i)
Buggy python submission (verdict: Runtime Error):
A: a = [int(x) for x in input().split(" ")]
print("bust") if sum(a) >= 22 else print("win")

Fixed submission:
a = [int(x) for x in input().split(" ")]
print("bust") if sum(a) >= 22 else print("win")
Buggy python submission (verdict: Runtime Error):
s = input()
c = 0
first, second = s[:len(s)//2], s[(len(s)+1)//2:]
if first == reversed(second):
    print(c)
else:
    for x in range(len(first)):
        if first[x] != second[len(second)-x-1]:
            count += 1
    print(c)

Fixed submission:
s = input()
c = 0
first, second = s[:len(s)//2], s[(len(s)+1)//2:]
if first == reversed(second):
    print(c)
else:
    for x in range(len(first)):
        if first[x] != second[len(second)-x-1]:
            c += 1
    print(c)

Buggy python submission (verdict: Runtime Error):
s = input()
c = 0
first, second = s[:len(s)//2], s[(len(s)+1)//2:]
if f == reversed(second):
    print(c)
else:
    for x in range(len(first)):
        if first[x] != second[len(second)-x-1]:
            count += 1
    print(c)

Fixed submission:
s = input()
c = 0
first, second = s[:len(s)//2], s[(len(s)+1)//2:]
if first == reversed(second):
    print(c)
else:
    for x in range(len(first)):
        if first[x] != second[len(second)-x-1]:
            c += 1
    print(c)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
print(a+b+c+9 * max(a, b, c))


Fixed submission:
a,b,c= map(int,input().split())
print(a+b+c+9 * max(a, b, c))
Buggy python submission (verdict: Runtime Error):
import math
n=input()
a=map(int,input().split())

a.sort()

print(a[-1]-a[0])


Fixed submission:
import math

n=input()
a=sorted(map(int,input().split()))


print(a[-1]-a[0])

Buggy python submission (verdict: Runtime Error):
import math

a=map(int,input().split())

a.sort()

print(a[-1]-a[0])


Fixed submission:
import math

n=input()
a=sorted(map(int,input().split()))


print(a[-1]-a[0])
Buggy python submission (verdict: Runtime Error):
import math

l=[]

for i in range(3):
    a=input()
    l.append(a)

print(len(set(l)))


Fixed submission:
import math

a,b,c=input().split()
l=[a,b,c]


print(len(set(l)))
Buggy python submission (verdict: Runtime Error):
def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a
    return gcd(b, a % b) if b else a


def sum_seq1(l: int, r: int)->int:
    if r < l:
        return 0
    return r*(r+1) // 2 - l*(l-1) // 2


def sum_difference(N: int, X: int, D: int)->int:
    if D == 0:
        if X == 0:
            return 1
        return N+1

    # D != 0
    D = abs(D)

    g = gcd(X, D)
    a, b = D // g, -X // g

    if a < 0:
        a *= -1
        b *= -1

    i_range = [(float('inf'), -float('inf'))] * (N+1)

    ans = 0
    for k in range(N+1):
        kl, kr = i_range[k]
        nl = sum_seq1(0, k-1)
        nr = sum_seq1(N-k, N-1)
        # print('k: ({}, {}), n: ({}, {})'.format(kl, kr, nl, nr))

        if k+a <= N:
            i_range[k+a] = (b+min(kl, nl), b+max(kr, nr))

        if kr == -float('inf'):
            ans += nr - nl + 1
        elif kr < nl or nr < kl:
            ans += nr - nl + 1
        elif nl <= kl and kr <= nr:
            ans += (nr-nl+1) - (kr-kl+1)
        elif kl <= nl:
            ans += max(0, nr-kr)
        else:
            ans += kl-nl

    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    ans = sum_difference(N, X, D)
    print(ans)


Fixed submission:
def gcd(a: int, b: int)->int:
    a, b = abs(a), abs(b)
    if a < b:
        a, b = b, a
    return gcd(b, a % b) if b else a


def sum_seq1(l: int, r: int)->int:
    if r < l:
        return 0
    return r*(r+1) // 2 - l*(l-1) // 2


def sum_difference(N: int, X: int, D: int)->int:
    if D == 0:
        if X == 0:
            return 1
        return N+1

    # D != 0
    g = gcd(X, D)
    a, b = D // g, -X // g

    if a < 0:
        a *= -1
        b *= -1
    i_range = [(float('inf'), -float('inf'))] * (N+1)

    ans = 0
    for k in range(N+1):
        kl, kr = i_range[k]
        nl = sum_seq1(0, k-1)
        nr = sum_seq1(N-k, N-1)
        # print('k: ({}, {}), n: ({}, {})'.format(kl, kr, nl, nr))

        if k+a <= N:
            i_range[k+a] = (b+min(kl, nl), b+max(kr, nr))

        if kr == -float('inf'):
            ans += nr - nl + 1
        elif kr < nl or nr < kl:
            ans += nr - nl + 1
        elif nl <= kl and kr <= nr:
            ans += (nr-nl+1) - (kr-kl+1)
        elif kl <= nl:
            ans += max(0, nr-kr)
        else:
            ans += kl-nl

    return ans


if __name__ == "__main__":
    N, X, D = map(int, input().split())
    ans = sum_difference(N, X, D)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def digits_parade(S: str)->int:
    MOD = 10**9 + 7
    DIV = 13
    # dp[i][j] = S の i 桁目までを利用してできる整数で 13 で割ったあまりが j になる組み合わせ
    dp = [[0] * DIV for _ in range(len(S)+1)]
    dp[0][0] = 1

    # digit: 10^n % 13 を計算するための変数
    digit = 1

    for i, c in enumerate(reversed(S)):
        if c == '?':
            for n in range(10):
                d = (n * digit) % DIV
                for j in range(DIV):
                    dp[i+1][(j+d) % DIV] += dp[i][j]
                    dp[i+1][(j+d) % DIV] %= MOD
        else:
            d = (int(c) * digit) % DIV
            for j in range(DIV):
                dp[i+1][(j+d) % DIV] += dp[i][j]
                dp[i+1][(j+d) % DIV] %= MOD

        digit = (digit * 10) % DIV

    return dp[len(S)][5]


if __name__ == "__main__":
    S = input()
    ans = digits_parade(S)
    print(ans)


Fixed submission:
def digits_parade(S: str)->int:
    MOD = 10**9 + 7
    DIV = 13
    # dp[i][j] = S の i 桁目までを利用してできる整数で 13 で割ったあまりが j になる組み合わせ
    dp = [[0] * DIV for _ in range(len(S)+1)]
    dp[0][0] = 1

    # digit: 10^n % 13 を計算するための変数
    digit = 1

    for i, c in enumerate(reversed(S)):
        if c == '?':
            for n in range(10):
                d = (n * digit) % DIV
                for j in range(DIV):
                    dp[i+1][(j+d) % DIV] += dp[i][j]
                    dp[i+1][(j+d) % DIV] %= MOD
        else:
            d = (int(c) * digit) % DIV
            for j in range(DIV):
                dp[i+1][(j+d) % DIV] += dp[i][j]
                dp[i+1][(j+d) % DIV] %= MOD

        digit = (digit * 10) % DIV

    return dp[len(S)][5]


if __name__ == "__main__":
    S = input()
    ans = digits_parade(S)
    print(ans)