Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 1000000007;

dp=np.zeros(13*2,dtype='int64')

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=np.zeros(13,dtype='int64')
c=s[0]

if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp.fill(0)
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r.fill(0)
	if (c==-1):
		w=np.sum(dp[4:14])
		for j in range(13):
			r[j]+=w
			w+=dp[j+1]
			w-=dp[4+j]
	else:
		r+=dp[13-c:26-c]
print (r[5]%MOD)


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 1000000007;

dp=np.zeros(13*2,dtype='int64')

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=np.zeros(13,dtype='int64')
c=s[0]

if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp.fill(0)
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r.fill(0)
	if (c==-1):
		for j in range(10):r+=dp[13-j:26-j]
	else:
		r+=dp[13-c:26-c]
print (r[5]%MOD)


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 1000000007;


def initMod(c):
	a=np.zeros(13,dtype='int64')
	if (c!=-1):
		a[c]=1
	else:
		for i in range(10):a[i]=1
	return a;


s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=initMod(s[0])

for i in range(1,n):
	dp=np.zeros(13*2,dtype='int64')
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=np.zeros(13,dtype='int64')
	if (c==-1):
		for j in range(10):r+=dp[13-j:26-j]
	else:
		r+=dp[13-c:26-c]
print (r[5]%MOD)

Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;
 
s = input()
 
n=len(s)
 
if n<1 or n>10**5:
	print ('Illegal')
	exit()
b=[0]*13
#pr=[0]*13

p=1

for i in range(n):
	ix=n-1-i
	if(s[ix]=="?"):
		c=-1
	else:
		c=int(s[ix])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[(p*j)%13]=1
		else:
			b[(p*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[(k+p*j)%13]+=pr[k]
		else:
			for k in range(13):
				b[(k+p*c)%13]+=pr[k]
 
	if (i%30==0 or i==n-1):
		for k in range(13):b[k]%=MOD
	p=p*10%13
	pr=b
	b=[0]*13
#	print (pr)
#	for k in range(13):
#		pr[k]=b[k]
#		b[k]=0
#	print (pr)
print (pr[5])
 

Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;
 
s = input()
 
n=len(s)
 
if n<1 or n>10**5:
	print ('Illegal')
	exit()
b=[0]*13
pr=[0]*13

p=1

for i in range(n):
	ix=n-1-i
	if(s[ix]=="?"):
		c=-1
	else:
		c=int(s[ix])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[(p*j)%13]=1
		else:
			b[(p*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[(k+p*j)%13]+=pr[k]
		else:
			for k in range(13):
				b[(k+p*c)%13]+=pr[k]
 
	if (i%30==0 or i==n-1):
		for k in range(13):b[k]%=MOD
	p=p*10%13
#	print (pr)
	for k in range(13):
		pr[k]=b[k]
		b[k]=0
#	print (pr)
print (pr[5])


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()

#a=[-1]*len(s)
#b=np.zeros((n+1, 13), dtype = 'int64')
#p=np.zeros(n,dtype=int)

b=[[0 for i in range(13)] for j in range(n+1)]
#p=[0]*n


p=1
#for i in reversed(range(n)):
#	p[i]=x%13
#	x=p[i]*10
	
for i in range(n):
	ix=n-1-i
	if(s[ix]=="?"):
		c=-1
	else:
		c=int(s[ix])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p*j)%13]=1
		else:
			b[0][(p*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p*c)%13]+=b[i-1][k]

	if (i%30==0 or i==n-1):
		for k in range(13):b[i][k]%=MOD
	p=p*10%13
#	print (b[i])
#	print (b[i+1])

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



Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()

#a=[-1]*len(s)
#b=np.zeros((n+1, 13), dtype = 'int64')
#p=np.zeros(n,dtype=int)

b=[[0 for i in range(13)] for j in range(n+1)]
#p=[0]*n


p=1
#for i in reversed(range(n)):
#	p[i]=x%13
#	x=p[i]*10
	
for i in range(n):
	ix=n-1-i
	if(s[ix]=="?"):
		c=-1
	else:
		c=int(s[ix])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p*j)%13]=1
		else:
			b[0][(p*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p*c)%13]+=b[i-1][k]

	for k in range(13):b[i][k]%=MOD
	p=p*10%13
#	print (b[i])
#	print (b[i+1])

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



Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):

MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()

#a=[-1]*len(s)
#b=np.zeros((n+1, 13), dtype = 'int64')
#p=np.zeros(n,dtype=int)

b=[[0 for i in range(13)] for j in range(n+1)]
#p=[0]*n


x=1
#for i in reversed(range(n)):
#	p[i]=x%13
#	x=p[i]*10
	
for i in range(n):
	p=(10**(n-1-i))%13
	if(s[i]=="?"):
		c=-1
	else:
		c=int(s[i])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p*j)%13]=1
		else:
			b[0][(p*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p*c)%13]+=b[i-1][k]

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

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



Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()

#a=[-1]*len(s)
b=np.zeros((n+1, 13), dtype = 'int64')
p=np.zeros(n,dtype=int)
#b=[[0 for i in range(13)] for j in range(n+1)]
#p=[0]*n


x=1
for i in reversed(range(n)):
	p[i]=x%13
	x=p[i]*10
	
for i in range(n):
	if(s[i]=="?"):
		c=-1
	else:
		c=int(s[i])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p[i]*j)%13]=1
		else:
			b[0][(p[i]*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p[i]*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p[i]*c)%13]+=b[i-1][k]

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

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


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()

#a=[-1]*len(s)
b=np.zeros((n+1, 13), dtype = 'int64')
p=np.zeros(n,dtype=int)

b.shape
p.shape


x=1
for i in reversed(range(n)):
	p[i]=x%13
	x=p[i]*10
	
for i in range(n):
	if(s[i]=="?"):
		c=-1
	else:
		c=int(s[i])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p[i]*j)%13]=1
		else:
			b[0][(p[i]*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p[i]*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p[i]*c)%13]+=b[i-1][k]

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

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


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;

s = input()

n=len(s)

if n<1 or n>10**5:
	print ('Illegal')
	exit()


#a=[-1]*len(s)
b=[[0 for i in range(13)] for j in range(n+1)]
p=[0]*n

x=1
for i in reversed(range(n)):
	p[i]=x%13
	x=p[i]*10
	
for i in range(n):
	if(s[i]=="?"):
		c=-1
	else:
		c=int(s[i])
	if ( i== 0):
		if (c==-1):
			for j in range(10):
				b[0][(p[i]*j)%13]=1
		else:
			b[0][(p[i]*c)%13]=1
	else:
		if (c==-1):
			for j in range(10):
				for k in range(13):
					b[i][(k+p[i]*j)%13]+=b[i-1][k]
		else:
			for k in range(13):
				b[i][(k+p[i]*c)%13]+=b[i-1][k]

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

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


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007;

s = input()

if len(s)<1 or len(s)>10**5:
	print ('Illegal')
	exit()

n=len(s)

#a=[-1]*len(s)
b=[[0 for i in range(13)] for j in range(n+1)]
p=[0]*n

x=1
for i in reversed(range(n)):
	p[i]=x%13
	x=p[i]*10
	
for i in range(n):
	if(s[i]=="?"):
		c=-1
	elif(s[i]>="0" and s[i]<="9"):
		c=int(s[i])
	else:
		print (a[i]+"   Illegal")
		exit()
	if ( i== 0):
		for j in range(10):
			if (c!=-1 and c!=j): continue
			b[0][(p[i]*j)%13]=1
	else:
		for j in range(10):
			if (c!=-1 and c!=j): continue
			y=(p[i]*j)%13
			for k in range(13):
				b[i][(k+y)%13]+=b[i-1][k]


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

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


Fixed submission:
MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)