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: Runtime Error)

//------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define PRINT(V)       \
    for (auto v : (V)) \
    cout << v << " "
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//math
//------------------------------------------
int QP(int a, int b)
{
    int ans = 1;
    do
    {
        if (b & 1)
            ans = 1ll * ans * a % MOD;
        a = 1ll * a * a % MOD;
    } while (b >>= 1);
    return ans;
}
int QP(int a, int b, int MOD)
{
    int ans = 1;
    do
    {
        if (b & 1)
            ans = 1ll * ans * a % MOD;
        a = 1ll * a * a % MOD;
    } while (b >>= 1);
    return ans;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

//debug
//------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;


int calc(int k, int i)
{
    //k*10**(i+1)を13でわったあまり
    int n=i%6;
    int V[6];
    V[0]=10;
    V[1]=9;
    V[2]=12;
    V[3]=3;
    V[4]=4;
    V[5]=1;
    int ans=V[n];
    ans = ans*k%13;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    string S;
    cin >> S;
    ll dp[10001][13];

    char c = S.back();
    int N=S.size();
    //initislization
    REP(i, 13)
    {
        dp[0][i] = 0;
        if (c == '?')
        {
            if (i <= 9)
                dp[0][i] = 1;
        }
        else
        {
            if (i == c - 48)
            {
                dp[0][i] = 1;
            }
        }
    }
    //update
    REP(i, N - 1)
    {
        c = S[N - 2 - i];
        REP(j, 13)
        {
            dp[i + 1][j] = 0;
            if (c == '?')
            {
                REP(k, 10)
                {
                    int num = j - calc(k,i);
                    int index = num >= 0 ? num : 13 + num;
                    dp[i + 1][j] += dp[i][index];
                }
            }
            else
            {
                int num = j - calc((int)c-48,i);
                int index = num >= 0 ? num : 13 + num;
                dp[i + 1][j] = dp[i][index];
            }
            dp[i+1][j]=dp[i+1][j]%MOD;
        }
    }
    cout << (int)dp[N - 1][5] << endl;
    return 0;
}