Problem:
Score : 400 points

Problem Statement

Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.

Since the answer can be enormous, print the count modulo 10^9+7.

Constraints

S is a string consisting of digits (0, ..., 9) and ?.

1 \leq |S| \leq 10^5

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of integers satisfying the condition, modulo 10^9+7.

Sample Input 1

??2??5

Sample Output 1

768

For example, 482305, 002865, and 972665 satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only 044 satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888

Solution in Python (3.4.3) (judge verdict: Time Limit Exceeded)

#import time
import numpy as np

#st = time.time()

S = list(input())

hatena = S.count('?')
hatena_list = [len(S)-1-i for i, x in enumerate(S) if x == '?']

hatena_list_np = np.array(hatena_list)

#print(hatena_list)  
l_np = np.zeros((hatena+1, 13))
#l = [[0]*13 for _ in range(hatena+1)]
 
SS = S.copy()
for i in range(len(S)):
    if SS[i] == '?':
        SS[i] = '0'
SS_13 = int(''.join(SS))%13
#l[0][SS_13] = 1
l_np[0, SS_13] = 1

def function(x):
    if x<0:
        x = 13+x
    return x
 
def function_np(x):
    return x + (x<0)*13

def power_mod_13(base, p):
    ret = 1
    while(p!=0):
        ret = ret * base % 13 if p%2 else ret
        base = base * base % 13
        p //= 2
    return ret % 13

for i in range(1,hatena+1):
    s = hatena_list[i-1]
    j_np = np.array(range(0,10))
    SS_13_np = (power_mod_13(10, s) * j_np) % 13
    k_np = np.array(range(0,13))
    #l_np[i, k_np] += 
    temp = function_np(k_np.reshape((-1,1)) - SS_13_np.reshape(1,-1))
    l_np[i] = np.sum(l_np[i-1, temp], axis=1) % 1000000007
    #for j in range(0,10):
    #    SS_13 = 10**s *j %13
    #    for k in range(0,13):
    #        l[i][k] += l[i-1][function(k-SS_13)] % 1000000007
    #        l[i][k] %= 1000000007
       
#print(l[-1][5])
print(int(l_np[-1][5]))