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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define int long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

ll mem_sec[2][3];
ll sum_n[2];
signed main(){
    string s;
    cin>>s;
    ll sz = s.size();
    vector<vector<ll>> mem_n(2); 
    ll ct = 0;
    string sec_s;
    while(sz>0){
        rep(i,min(3LL,sz)){
            sec_s = s.substr(sz-1-i,1);
            if(sec_s =="?"){
                sec_s = "0";
                mem_sec[ct%2][i]++;
            }
            sum_n[ct%2] += stoi(sec_s)*pow(10,i);
        }
        ct++;
        sz -=3;
        if(sz>0) s = s.substr(0,sz);
    }
    ll smod = (sum_n[0]-sum_n[1])%13;
    while(smod<0) smod +=13;
    // cout<<smod<<"\n";
    ll t_mem[2][13];
    rep(i,2) rep(j,13) t_mem[i][j]=0;
    ll bai[2][3] = {{1,10,100},{-1,-10,-100}};
    bool f=0;
    ll tmod;
    rep(g,2) rep(h,3){
        rep(i,mem_sec[g][h]){
            if(f==0){
                rep(j,10){
                    tmod = (j*bai[g][h]+1300)%13; 
                    t_mem[0][tmod]=1;
                }
                f=1;
            }else{
                rep(j,13){
                    t_mem[1][j]=t_mem[0][j];
                    t_mem[0][j]=0;
                }
                rep(j,13){
                    rep(k,10){
                        tmod = (j+k*bai[g][h]+1300)%13; 
                        t_mem[0][tmod] += t_mem[1][j];
                        t_mem[0][tmod] %= mod;
                    }
                }
            }
        }
    }
    ll ttt = 5-smod;
    if(ttt<0) ttt+=13;
    if(f==0) {
        cout<<(smod%13==5)<<"\n";
    }else cout<<t_mem[0][ttt]<<"\n";
    // rep(i,13) cout<<t_mem[0][i]<<endl;
}