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: Wrong Answer)

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
//#include <complex>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
//const ll INF = 1e9;
const ll MOD = 1000000000 + 7;
//const double EPS = 1e-9;
//const double PI = acos(-1);
 
ll ten[100100];
 
void solve() {
    string s;
    cin >> s;
    int n = s.length();
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?')
            a[i] = -1;
        else 
            a[i] = s[i] - '0';
    }
    
    ten[0] = 1;
    for (int i = 1; i < 100100; ++i)
        ten[i] = ten[i - 1] * 10 % MOD;
 
    vector<vector<ll>> dp(n + 1, vector<ll>(13, 0));
    dp[n][0] = 1;
    for (ll i = n - 1; i >= 0; --i) {
        if (a[i] == -1) {
            for (ll k = 0; k < 13; ++k)
                for (ll d = 0; d <= 9; ++d)
                    dp[i][(ten[n - 1 - i] * d + k) % 13] = (dp[i][(ten[n - 1 - i] * d + k) % 13] + dp[i + 1][k]) % MOD;
        } else {
            for (ll k = 0; k < 13; ++k)
                dp[i][(ten[n - 1 - i] * a[i] + k) % 13] = (dp[i][(ten[n - 1 - i] * a[i] + k) % 13] + dp[i + 1][k]) % MOD;
        }
    }
    cout << dp[0][5] % MOD;
}   
 
 
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    solve();
}