Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
 
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1])

Fixed submission:
H, N = map(int, input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]
 
# dp[damage] := モンスターに damage を与えるために必要な最小コスト
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S =list(str(input()))
a=[]
for i in range(10):
    for k in range(N-2):
        if str(i)==S[k]:
            for u in range(10):
                for j in range(k+1,N-1):
                    if str(u)==S[j]:
                        for y in range(10):
                            for h in range(j+1,N):
                                if str(y)==S[h]:
                                    a.append(S[k]+S[j]+S[h])
print(len(set(a)))

Fixed submission:
N = int(input())
S =list(str(input()))
a=[]
ans=0
for i in range(10):
    for u in range(10):
        for y in range(10):
            moji=[str(i),str(u),str(y)]
            ti=0
            for t in range(N):
                if S[t]==moji[ti]:
                    ti+=1
                    if ti==3:
                        break
            if ti==3:
                ans+=1
                            
                
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#6
N = int(input())
S =list(str(input()))
a=[]
for i in range(N-2):
    for u in range(i+1,N-1):
        for y in range(u+1,N):
            a.append(S[i]+S[u]+S[y])
print(len(set(a)))

Fixed submission:
N = int(input())
S =list(str(input()))
a=[]
ans=0
for i in range(10):
    for u in range(10):
        for y in range(10):
            moji=[str(i),str(u),str(y)]
            ti=0
            for t in range(N):
                if S[t]==moji[ti]:
                    ti+=1
                    if ti==3:
                        break
            if ti==3:
                ans+=1
                            
                
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
h= list(map(int, input().split()))
INF=float('inf')
dp=[INF]*(N)
dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,N):
    for k in range(1,K+1):
        dp[i]=min(dp[i-k]+abs(h[i]-h[i-k]),dp[i])
print(dp[-1])

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

DP=[0]*(N)
DP[0]=0
DP[1]=abs(h[1]-h[0])
#print(DP)
for i in range(2,N):
    DP[i]=DP[i-1]+abs(h[i]-h[i-1])
    for u in range(1,K+1):
        if i-u>=0:
            DP[i]=min(DP[i],DP[i-u]+abs(h[i]-h[i-u]))
        else:
            break
    #print(DP)
print(DP[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
t = str(input())

dp=[[0 for i in range(len(s)+1)] for j in range(len(t)+1)] 

for i in range(1,len(s)+1):
    for u in range(1,len(t)+1):
        if s[i-1]==t[u-1]:
            dp[u][i]=dp[u-1][i-1]+1
        else:
            dp[u][i]=max(dp[u-1][i],dp[u][i-1])
lenth=dp[-1][-1]
i=len(s)
j=len(t)
ans=""
while lenth>0:
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1
        j-=1
        lenth-=1
    elif dp[j][i]==dp[j-1][i]:
        j-=1
    else:
        i-=1
    lenth=dp[j][i]
print(ans)

Fixed submission:
s = str(input())
t = str(input())

dp=[[0 for i in range(len(s)+1)] for j in range(len(t)+1)] 

for i in range(1,len(s)+1):
    for u in range(1,len(t)+1):
        if s[i-1]==t[u-1]:
            dp[u][i]=dp[u-1][i-1]+1
        else:
            dp[u][i]=max(dp[u-1][i],dp[u][i-1])
lenth=dp[-1][-1]
i=len(s)
j=len(t)
ans=""
while lenth>0:
    if s[i-1]==t[j-1]:
        ans=s[i-1]+ans
        i-=1
        j-=1
        lenth-=1
    elif dp[j][i]==dp[j-1][i]:
        j-=1
    else:
        i-=1
    lenth=dp[j][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(float, input().split()))
dp=[[[0.0] *(N+2) for _ in range(N+2)] for _ in range(N+2)]
one,two,three=a.count(1),a.count(2),a.count(3)
for k in range(three+1):
    for j in range(N+1):
        for i in range(N+1):
            if k==0 and j==0 and i==0:
                continue
            num=N
            if i>0:
                num+=dp[i-1][j][k]*i
            if j>0:
                num+=dp[i+1][j-1][k]*j
            if k>0:
                num+=dp[i][j+1][k-1]*k
            dp[i][j][k]=num/(k+j+i)
print(dp[one][two][three])

Fixed submission:
N = int(input())
a = list(map(float, input().split()))
dp=[[[0.0] *(N+2) for _ in range(N+2)] for _ in range(N+2)]
one,two,three=a.count(1),a.count(2),a.count(3)
for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(N+1):
            if k==0 and j==0 and i==0:
                continue
            num=N
            if i>0:
                num+=dp[i-1][j][k]*i
            if j>0:
                num+=dp[i+1][j-1][k]*j
            if k>0:
                num+=dp[i][j+1][k-1]*k
            dp[i][j][k]=num/(k+j+i)
print(dp[one][two][three])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(float, input().split()))
dp=[[[0.0] *(N+2) for _ in range(N+2)] for _ in range(N+2)]
one,two,three=a.count(1),a.count(2),a.count(3)
for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if k==0 and j==0 and i==0:
                continue
            num=N
            if i>0:
                num+=dp[i-1][j][k]*i
            if j>0:
                num+=dp[i+1][j-1][k]*j
            if k>0:
                num+=dp[i][j+1][k-1]*k
            dp[i][j][k]=num/(k+j+i)
print(dp[one][two][three])

Fixed submission:
N = int(input())
a = list(map(float, input().split()))
dp=[[[0.0] *(N+2) for _ in range(N+2)] for _ in range(N+2)]
one,two,three=a.count(1),a.count(2),a.count(3)
for k in range(three+1):
    for j in range(two+three+1-k):
        for i in range(N+1):
            if k==0 and j==0 and i==0:
                continue
            num=N
            if i>0:
                num+=dp[i-1][j][k]*i
            if j>0:
                num+=dp[i+1][j-1][k]*j
            if k>0:
                num+=dp[i][j+1][k-1]*k
            dp[i][j][k]=num/(k+j+i)
print(dp[one][two][three])
Buggy python submission (verdict: Runtime Error):
N=int(input())
a = list(map(int, input().split()))

dp=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    dp[i][i]=a[i-1]
for j in range(1,N+1):
    for i in reversed(range(1,N+1)):
        if i>j:
            continue
        if i==j:
            dp[i][j]=a[i-1]
        if i<j:
            dp[i][j]=max(a[i-1]-dp[i+1][j],a[j-1]-dp[i][j-1])
print(dp[1][N]

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

dp=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(1,N+1):
    dp[i][i]=a[i-1]
for j in range(1,N+1):
    for i in reversed(range(1,N+1)):
        if i>j:
            continue
        if i==j:
            dp[i][j]=a[i-1]
        if i<j:
            dp[i][j]=max(a[i-1]-dp[i+1][j],a[j-1]-dp[i][j-1])
print(dp[1][N])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()
ans=0
for a in range(N):
    for b in range(bisect.bisect_right(B,A[a]),N):
        for c in range(bisect.bisect_right(C,B[b]),N):
            ans+=1
print(ans)

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

A.sort()
B.sort()
C.sort()
ans=0
for b in range(N):
    a=bisect.bisect_left(A,B[b])
    c=N-bisect.bisect_right(C,B[b])
    ans+=a*c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()
ans=0
for a in range(N):
    for b in range(bisect.bisect_right(B,A[a]),N):
        for c in range(bisect.bisect_right(C,B[b]),N):
            
            if A[a]<B[b]<C[c]:
                ans+=1
print(ans)

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

A.sort()
B.sort()
C.sort()
ans=0
for b in range(N):
    a=bisect.bisect_left(A,B[b])
    c=N-bisect.bisect_right(C,B[b])
    ans+=a*c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()
ans=0
for a in range(N):
    for b in range(bisect.bisect_right(B,A[a]),N):
        for c in range(bisect.bisect_right(C,B[b]),N):
            
            if A[a]<B[b]<C[c]:
                ans+=1
print(ans)

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

A.sort()
B.sort()
C.sort()
ans=0
for b in range(N):
    a=bisect.bisect_left(A,B[b])
    c=N-bisect.bisect_right(C,B[b])
    ans+=a*c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
nums = list(map(lambda x: int(x), input().split(" ")))
n = nums[0]
k = nums[1]
ps = list(map(lambda x: (int(x) + 1) / 2, input().split(" ")))
res = 0.0
for i in range(n - k + 1):
    res = max(res, sum(ps[i:i+k]))
print(res)

Fixed submission:
nums = list(map(lambda x: int(x), input().split(" ")))
n = nums[0]
k = nums[1]
ps = list(map(lambda x: (int(x) + 1) / 2, input().split(" ")))
res = 0.0
su = 0.0
sums = [0] * n
for i, s in enumerate(ps):
    su = su + s
    sums[i] = su
for i in range(n - k + 1):
    if i == 0:
        res = sums[k - 1]
    else:
        res = max(res, sums[i + k - 1] - sums[i - 1] )
print(res)
Buggy python submission (verdict: Runtime Error):
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
        
    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))

Fixed submission:
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
    if plus == 0:
        break

    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))
Buggy python submission (verdict: Runtime Error):
count = int(input())
l = []
m = 0
c = 0
for i in range(count):
  val = int(input())
  m = max(m, val)
  if val >= m:
    c = c + 1
print(c)
           

Fixed submission:
count = int(input())
m = 0
c = 0
vals = input().split(" ")
for i in vals:
  val = int(i)
  m = max(m, val)
  if val >= m:
    c = c + 1
print(c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int.input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l.sort()
print(abs(l[0]-l[len(l)-1]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
f=[]
for x in l:
	f.append(x[0]==x[1])
l=f.copy()
i=0
while i<n:
	j=0
	while i+j<n and l[i+j]==l[i] and l[i]:
		j+=1 
	if j>2:
		print('Yes')
		break	
	i+=j
else:
	print('No')
	

Fixed submission:
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
f=[]
for x in l:
	f.append(x[0]==x[1])
l=f.copy()
i=0
while i<n:
	j=1
	while i+j<n and l[i+j]==l[i] and l[i]:
		j+=1 
	if j>2:
		print('Yes')
		break	
	i+=j
else:
	print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from functools import  reduce
n,k=map(int,input().split())
l=list(map(int,input().split()))
x=reduce(lambda x,y: x*y,l[:k])
temp=[x]
for i in range(k,len(l)):
	if l[i]<=l[i-k]:
		print('No')
	else:
		print('Yes')
		

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(k,len(l)):
	if l[i]<=l[i-k]:
		print('No')
	else:
		print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
from functools import  reduce
n,k=map(int,input().split())
l=list(map(int,input().split()))
x=reduce(lambda x,y: x*y,l[:k])
temp=[x]
for i in range(k,len(l)):
	x*=l[i]
	x//=l[i-k]
	temp.append(x)
for i in range(1,len(temp)):
	if temp[i]>temp[i-1]:
		print('Yes')
	else:
		print('No')

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(k,len(l)):
	if l[i]<=l[i-k]:
		print('No')
	else:
		print('Yes')
Buggy python submission (verdict: Runtime Error):
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')

MOD =    1000000007
MAX=2147483647
MIN=-2147483648
p=input
l,l1,l2,l3=[],[],[],[]
# for _ in range(o()):
n,k=io()
l=op()
x=y=0
i=0
fr=[0]*(2*(10**5))
while 1:
    if fr[l[i]]==0:
        l1.append(l[i])
        fr[l[i]]=1
        i=l[i]-1
    else:
        y=l1.index(l[i])
        x=len(l1)-y
        break
if k<=len(l1):
    print(l1[k-1])
else:
    k-=y
    k%=x
    print(l1[y+k-1])

Fixed submission:
from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
def o():
    return int(input())
def kl(con,x=0):
    if x==0:print('Yes') if con else print('No')
    elif x==1:print('yes') if con else print('no')
    elif x==2:print('YES') if con else print('NO')

MOD =    1000000007
MAX=2147483647
MIN=-2147483648
p=input
l,l1,l2,l3=[],[],[],[]
# for _ in range(o()):
n,k=io()
l=op()
x=y=0
i=0
fr=[0]*(200002)
while 1:
    if fr[l[i]]==0:
        l1.append(l[i])
        fr[l[i]]=1
        i=l[i]-1
    else:
        y=l1.index(l[i])
        x=len(l1)-y
        break
if k<=len(l1):
    print(l1[k-1])
else:
    k-=y
    k%=x
    if k==0:
        k=x
    print(l1[y+k-1])
Buggy python submission (verdict: Runtime Error):
s=input()
if s=="ABC":
  print("ARC")
else:
  print("ABC)

Fixed submission:
s=input()
if s=="ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
from collections import  *
def io():
    return map(int,input().split())
def op():
    return list(map(int,input().split()))
n=int(input())
c=1
x=100
while 1:
    x=x*(1.01)
    x=int(x)
    if x==n:
        break
    c+=1
print(c)

Fixed submission:
n=int(input())
c=1
x=100
while x<n:
    x=x*(1.01)
    x=int(x)
    c+=1
print(c-1)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a==min(a,b);
  s=str(a)*b
  print(int(s))
else:  
  s=str(b)*a
  print(int(s))

Fixed submission:
a,b=map(int,input().split())
s1=str(b)*a
ss1=int(s1)
s2=str(a)*b
ss2=int(s2)
if ss1>ss2:
    print(s1)
else:
    print(s2)
Buggy python submission (verdict: Runtime Error):
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 10):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

print("\n".join(sorted(outs)))



Fixed submission:
import itertools

bells = [[], [[0]]] + [None for i in range(9)]
bell_n = [1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975]

def search(n):
    ret = []
    ret.append( [ 0 for _ in range(n) ] )
    for k in range(1,n):
        for bi in bells[k]:
            for ids in itertools.combinations(range(1,n), k):
                st = [0 for _ in range(n)]
                for i, id in enumerate(ids):
                    st[id] = bi[i] + 1
                ret.append(st)
    return ret

for i in range(2, 11):
    bells[i] = search(i)
    assert bell_n[i] == len(bells[i])

N = int(input())
table = "abcdefghij"
outs = []
for bi in bells[N]:
    out = ""
    for b in bi:
        out += table[b]
    outs.append(out)

print("\n".join(sorted(outs)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
Ss = []
for i in range(N):
    Ss.append((i+1, *input().split(" ")))

Ss.sort(key = lambda x: (x[1], -int(x[2])))
for i in range(N):
    print(Ss[i][0])


Fixed submission:
N = int(input())
Ss = []
for i in range(N):
    k = input().split(" ")
    Ss.append((i+1, k[0], k[1]))

Ss.sort(key = lambda x: (x[1], -int(x[2])))
for i in range(N):
    print(Ss[i][0])
Buggy python submission (verdict: Time Limit Exceeded):
# d
n = int(input())
print(sum(i%(i%n+1) for i in range(1, n+1)))

Fixed submission:
# d
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [b]
C = []
s = 0
for i in range(m+1):
    C += B[i]
    C = sorted(C, reverse = True)[:m-i+1]
    if C: s += C.pop(0)
print(s)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [-b]
C = []
s = 0
for i in range(m+1):
    for b in B[i]: heappush(C, b)
    if C: s += heappop(C)
print(-s)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [b]
C = []
s = 0
for i in range(m+1):
    C += B[i]
    C = sorted(C, reverse = True)[:m-i+1]
    if C: s += C.pop(0)
print(s)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [-b]
C = []
s = 0
for i in range(m+1):
    for b in B[i]: heappush(C, b)
    if C: s += heappop(C)
print(-s)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [b]
C = []
s = 0
for i in range(m+1):
    C += B[i]
    C = sorted(C, reverse = True)
    if C: s += C.pop(0)
print(s)

Fixed submission:
from heapq import heappush, heappop
n, m = map(int, input().split())
B = [[] for _ in range(m+1)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m: B[a] += [-b]
C = []
s = 0
for i in range(m+1):
    for b in B[i]: heappush(C, b)
    if C: s += heappop(C)
print(-s)
Buggy python submission (verdict: Runtime Error):
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

Fixed submission:
a, b = map(int, input().split())
if a%2 == b%2:
    print(int((a+b)/2))
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

Fixed submission:
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

Buggy python submission (verdict: Runtime Error):
P=[1,10,9,12,3,4]
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%(10**9+7)
    return B
S=reversed(input())
A=[0]
p=0
for s in S
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
    p=(p+1)%6
print(A[5])


Fixed submission:
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

Buggy python submission (verdict: Time Limit Exceeded):
P=[1,10,9,12,3,4]
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p%6]))%13
            B[c]=(B[c]+A[i])%(10**9+7)
    return B
S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])

Fixed submission:
P=[1,10,9,12,3,4]
m=10**9+7
def f(A,p,N):
    if p==0:return [1&(i in N) for i in range(13)]
    p%=6
    B=[0]*13
    for n in N:
        for i in range(13):
            c=(i+(n*P[p]))%13
            B[c]=(B[c]+A[i])%m
    return B

S=reversed(input())
A=[0]
for p,s in enumerate(S):
    if s=="?":A=f(A,p,range(10))
    else:A=f(A,p,[int(s)])
print(A[5])
Buggy python submission (verdict: Runtime Error):
# B - Golden Apple

from math import ceil 
N, D = map(int, input().split())
print(ceil(N/(2*D+1)))

Fixed submission:
# A - Dodecagon

r = int(input())
print(3*r**2)

Buggy python submission (verdict: Runtime Error):
N, D = map(int, input().split())
print((N+2*D)//(2*D+1))

Fixed submission:
# A - Dodecagon

r = int(input())
print(3*r**2)

Buggy python submission (verdict: Runtime Error):
# B - Golden Apple

N, D = map(int, input().split())
# print(int((N+2*D)/(2*D+1)))
print((N+2*D)//(2*D+1))

Fixed submission:
# A - Dodecagon

r = int(input())
print(3*r**2)

Buggy python submission (verdict: Runtime Error):
# B - Golden Apple

N, D = map(int, input().split())
print(int((N+2*D)/(2*D+1)))

Fixed submission:
# A - Dodecagon

r = int(input())
print(3*r**2)

Buggy python submission (verdict: Runtime Error):
# B - Golden Apple

N, D = map(int, input().split())
print(int((N+2*D)/(2*D+1)))

Fixed submission:
# A - Dodecagon

r = int(input())
print(3*r**2)