Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

Fixed submission:
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

modmemo = []
modmemo.append(1)
for idx in range(len(S)):
	modmemo.append((modmemo[len(modmemo) - 1] * 10) % 13)


for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			mod = (modmemo[len(S) - idx - 1] * num)%13
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i+mod)%13] += memo[idx][i] 
	else:
		num = int(ch)
		mod = (modmemo[len(S) - idx - 1] * num)%13
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i+mod)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

Fixed submission:
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

modmemo = []
modmemo.append(1)
for idx in range(len(S)):
	modmemo.append((modmemo[len(modmemo) - 1] * 10) % 13)


for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			mod = (modmemo[len(S) - idx - 1] * num)%13
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i+mod)%13] += memo[idx][i] 
					memo[idx+1][(i+mod)%13] %= MOD
	else:
		num = int(ch)
		mod = (modmemo[len(S) - idx - 1] * num)%13
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i+mod)%13] += memo[idx][i] 
				memo[idx+1][(i+mod)%13] %= MOD

print(memo[len(S)][5]%MOD)

Fixed submission:
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

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

def modpow(ori, po):
	res = 1;
	while(po > 0):
		if(po&1):
			res *= ori;
			res %= 13;
		ori *= ori;
		ori %= 13;
		po >>= 1;
	return res;


S = input()
memo = [[0] * 13 for i in range(len(S)+1)]

memo[0][0] = 1
for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			mod = (modpow(10, (len(S) - idx - 1)) * num)%13
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i+mod)%13] += memo[idx][i] 
					memo[idx+1][(i+mod)%13] %= MOD
	else:
		num = int(ch)
		mod = (modpow(10, (len(S) - idx - 1)) * num)%13
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i+mod)%13] += memo[idx][i] 
				memo[idx+1][(i+mod)%13] %= MOD

print(memo[len(S)][5]%MOD)

Fixed submission:
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)

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

S = input()
memo = [[0] * 13 for i in range(len(S)+1)]

memo[0][0] = 1
for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			mod = ((10**(len(S) - idx - 1)) * num)%13
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i+mod)%13] += memo[idx][i] 
					memo[idx+1][(i+mod)%13] %= MOD
	else:
		num = int(ch)
		mod = ((10**(len(S) - idx - 1)) * num)%13
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i+mod)%13] += memo[idx][i] 
				memo[idx+1][(i+mod)%13] %= MOD

print(memo[len(S)][5]%MOD)

Fixed submission:
MOD = 1000000007
S = input()
memo = [[0] * 13 for i in range(len(S)+1)]
memo[0][0] = 1

for idx in range(len(S)):
	ch = S[idx]
	if(ch == '?'):
		for num in range(10):
			for i in range(13):
				if(memo[idx][i] > 0):
					memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	else:
		num = int(ch)
		for i in range(13):
			if(memo[idx][i] > 0):
				memo[idx+1][(i*10+num)%13] += memo[idx][i] 
	
	for i in range(13):
		memo[idx+1][i] %= MOD

print(memo[len(S)][5]%MOD)