stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define fix(f,n) std::fixed<<std::setprecision(n)<<f

#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long int ll;

typedef unsigned long long int ull;

#define vi vector<int>

#define pii pair<int,int>

#define vii vector<pii>

#define max(a,b) ((a>b)?a:b)

#define min(a,b) ((a>b)?b:a)

#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)

#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)

#define REP(i,a,n) for(ll i=a;i<n;i++)

#define pb push_back

#define mp make_pair



ll dp[100000][13];

string a;



ll gs(int ind,int n,int sum){

    if(ind==n){

        //cout << "in " << sum << endl;

        return (sum%13==5 ? 1:0);

    }

    if(dp[ind][sum%13]!=-1){

        return dp[ind][sum%13]%1000000007;

    }

    if(a[ind]!='?'){

        return dp[ind][sum%13]=gs(ind+1,n,((sum*10)+a[ind]-'0')%13)%1000000007;

    }

    ll res=0;

    for(int i=0 ; i<=9 ; i++){

        res+=gs(ind+1,n,((sum*10)+i)%13);

        //cout << i << " " << res << endl;

        res%=1000000007;

    }

    return dp[ind][sum%13]=res%1000000007;

}



int main(){

	fast;

	int test=1;

	//cin >> test;

	while(test--){

	    cin >> a;

	    memset(dp,-1,sizeof dp);

	    cout << gs(0,a.length(),0) << endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 13

#define M 1000000007

#define L 10



char s[111111];

int g[N][L];



int main()

{		

	long long d[2][N] = {1};

	int i, j, x, p0, p1;

	

	for(i = x = 0; i < N; i++, x += L){

		for(j = 0; j < L; j++){

			g[i][j] = (x + j) % N;

		}

	}

	

	scanf("%s", s);

	for(i = 0, p0 = 0, p1 = 1; s[i]; i++, p0 = !p0, p1 = !p1){

		if(s[i] != '?'){

			x = s[i] - 48;

			for(j = 0; j < N; j++){

				d[p1][g[j][x]] = d[p0][j];

			}

		}

		else{

			for(j = 0; j < N; j++) d[p1][j] = 0;

			for(x = 0; x < L; x++){

				for(j = 0; j < N; j++) d[p1][g[j][x]] += d[p0][j]; 

			}

			for(j = 0; j < N; j++) d[p1][j] %= M;

		}

	}

	printf("%lld\n", d[p0][5]);

		

				

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = pow(10,9) + 7;

 

string S;

int dp[100002][15];

 

ll solve(int pos, int rem) {

    if(pos == S.size()) return rem == 5;

    if(dp[pos][rem] != -1) return dp[pos][rem];

    ll ans(0);

    if(S[pos] == '?') {

        for(int i(0); i < 10; ++i) {

            ans += solve(pos + 1, (rem * 10 + i) % 13) % mod;

        }

    }

    else ans += solve(pos + 1, (rem * 10 + S[pos] - '0') % 13) % mod;

    return dp[pos][rem] = ans % mod;

}

 

int main() {

	memset(dp, -1, sizeof dp);

    cin >> S;

    cout << solve(0, 0) << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = pow(10,9) + 7;

 

string S;

int dp[100005][13];

 

ll solve(int pos, int rem) {

    if(pos == S.size()) return rem == 5;

    if(dp[pos][rem] != -1) return dp[pos][rem];

    ll ans(0);

    if(S[pos] == '?') {

        for(int i(0); i < 10; ++i) {

            ans += solve(pos + 1, (rem * 10 + i) % 13) % mod;

        }

    }

    else ans += solve(pos + 1, (rem * 10 + S[pos] - '0') % 13) % mod;

    return dp[pos][rem] = ans % mod;

}

 

int main() {

	memset(dp, -1, sizeof dp);

    cin >> S;

    cout << solve(0, 0) << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);++i)

#define rrep(i,n) for(int i=1;i<(n);++i)

#define all(a) (a).begin(),(a).end()

#define rall(a) (a).rbegin(),(a).rend()

#define dunk(a) cout << (a) << "\n"

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

const int inf = 1001001001;

const int mod = 1000000007;



struct mint {

	ll x;

	mint() :x(0) {}

	mint(ll x) :x((x% mod + mod) % mod) {}

	// mint(ll x):x(x){}

	mint& fix() { x = (x % mod + mod) % mod; return *this; }

	mint operator-() const { return mint(0) - *this; }

	mint operator~() const { return mint(1) / *this; }

	mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this; }

	mint& operator-=(const mint& a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; }

	mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }

	mint& operator/=(const mint& a) { (x *= a.pow(mod - 2).x) %= mod; return *this; }

	mint operator+(const mint& a)const { return mint(*this) += a; }

	mint operator-(const mint& a)const { return mint(*this) -= a; }

	mint operator*(const mint& a)const { return mint(*this) *= a; }

	mint operator/(const mint& a)const { return mint(*this) /= a; }

	mint pow(ll t) const {

		if (!t) return 1;

		mint res = pow(t / 2);

		res *= res;

		return (t & 1) ? res * x : res;

	}

	bool operator<(const mint& a)const { return x < a.x; }

	bool operator==(const mint& a)const { return x == a.x; }

};



mint dp[100001][13];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.size();

	dp[0][0] = 1;

	rep(i, n) {

		int c = (s[i] == '?' ? - 1 : int(s[i] - '0'));

		rep(j, 10) {

			if (c != -1 && c != j) continue;

			rep(k, 13) {

				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];

			}

		}

	}

	mint ans = dp[n][5];

	printf("%d", ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);++i)

#define rrep(i,n) for(int i=1;i<(n);++i)

#define all(a) (a).begin(),(a).end()

#define rall(a) (a).rbegin(),(a).rend()

#define maxs(a, b) a = max(a, b)

#define mins(a, b) a = min(a, b)

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

const ll linf = 1001002003004005006ll;

const int inf = 1001001001;

const int mod = 1000000007;



ll dp[100001][13];



int main() {

	ios::sync_with_stdio(false);

	cin.tie(0);

	string s;

	cin >> s;

	int n = s.size();

	dp[0][0] = 1;

	rep(i, n) {

		int c = -1;

		if (s[i] != '?') c = s[i] - '0';

		rep(j, 10) {

			if (c != -1 && j != c) continue;

			rep(k, 13) {

				(dp[i + 1][(k * 10 + j) % 13] += dp[i][k]) %= mod;

			}

		}

	}

	cout << dp[n][5] % mod << endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



const long long MOD = 1000000007LL;

long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

long long fast_exp(long long base, long long exp, long long mod = MOD) {

    long long tot = 1;

    for(;exp > 0;exp >>= 1) {

       if((exp & 1) == 1) tot = tot * base % mod;

       base = base * base % mod;

    }

    return tot;

}



long long dp[100005][13];



int main(){



    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);



    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);



    // help i dont know digit dp



    string s; cin >> s;

    int n = s.size();



    dp[0][0] = 1;



    for(int i = 0; i < n; ++i){



        for(int rem = 0; rem < 13; ++rem){



            if(s[i] != '?'){

                //cout << "USING " << (rem + (s[i] - '0') * fast_exp(10, n - i, 13)) % 13 << " " << dp[i][rem] << endl;

                dp[i + 1][(rem + (s[i] - '0') * fast_exp(10, n - i - 1, 13)) % 13] = dp[i][rem];

                dp[i + 1][(rem + (s[i] - '0') * fast_exp(10, n - i - 1, 13)) % 13] %= MOD;

            } else {

                for(int dig = 0; dig < 10; ++dig){

                    dp[i + 1][(rem + dig * fast_exp(10, n - i - 1, 13)) % 13] += dp[i][rem];

                    dp[i + 1][(rem + dig * fast_exp(10, n - i - 1, 13)) % 13] %= MOD;

                    //cout << i + 1 << " " << rem << " " << dp[i + 1][(rem + dig * fast_exp(10, n - i, 13)) % 13] << endl;

                }

            }



        }



    }



    cout << dp[n][5] << "\n";





    return 0;



}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const long long MOD = 1000000007LL;



long long dp[100005][13];



int main(){



    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);



    string s; cin >> s;

    int n = s.size();



    dp[n][0] = 1;



    int ten_rem = 1;



    for(int i = n - 1; i >= 0; --i){

        for(int rem = 0; rem < 13; ++rem){

            if(s[i] != '?'){

                dp[i][(rem + (s[i] - '0') * ten_rem) % 13] = dp[i + 1][rem];

                dp[i][(rem + (s[i] - '0') * ten_rem) % 13] %= MOD;

            } else {

                for(int dig = 0; dig < 10; ++dig){

                    dp[i][(rem + dig * ten_rem) % 13] += dp[i + 1][rem];

                    dp[i][(rem + dig * ten_rem) % 13] %= MOD;

                }

            }

        }

        ten_rem = ten_rem * 10 % 13;

    }



    cout << dp[0][5] << "\n";





    return 0;



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include <vector>

#define REP(i, n) for (int i = 0; i < (int)n; ++i)

#define REPR(i, n) for (int i = n-1; i >= 0; --i)

#define REPx(x, a) for(auto x : a)

#define ALL(a) a.begin(), a.end()

#define SORT(a) sort(ALL(a))

#define SORTG(a) sort(ALL(a), greater<int>())

#define REVERSE(a) reverse(ALL(a))

#define bit_search(bit, n) REP(bit, 1<<n)

#define bit_check(bit, i) (bit>>i) & 1

#define setpre(n) fixed << setprecision(n)

#define ENDL cout << endl;

using namespace std;

using ll = long long;

using PII = pair<int, int>;

using VP = vector<PII>;

using VI = vector<int>;

using VVI = vector<VI>;

using Vll = vector<ll>;

using VVll = vector<Vll>;

using VC = vector<char>;

using VS = vector<string>;

using VB = vector<bool>;

const int INF = 1e9;

const ll mod = 1e9 + 7;



int POW(ll a, ll b, ll m)

{

    ll res = 1;

    while(b > 0)

    {

        if (b & 1) res = res * a % m;

        a = a * a % m;

        b >>= 1;

    }

    return (int)res;

}



int main() {

  string S;

  cin >> S;

  ll len = S.size();

  VVll dp(len, Vll(13, 0));

  REPR(i, len)

  {

    if (i == len - 1)

    {

        if (S.at(i) != '?')

        {

            REP(j, 13) if (S.at(i)-'0' == j) dp.at(i).at(j) = 1;

        }

        else REP(j, 10) dp.at(i).at(j) = 1;

        continue;

    }

    REP(j, 13)

    {

        if (S.at(i) == '?')

        {

            REP(s_i, 10)

            {

                dp.at(i).at(j) += dp.at(i+1).at((13 + j - ((s_i * POW(10, len-i-1, 13)) % 13)) % 13);

                dp.at(i).at(j) %= mod;

            }

        }

        else

        {

            dp.at(i).at(j) += dp.at(i+1).at((13 + j - (((S.at(i)-'0') * POW(10, len-i-1, 13)) % 13)) % 13);

            dp.at(i).at(j) %= mod;

        }

    }

  }

  cout << dp.at(0).at(5) << endl;



  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using ull = unsigned long long;



static const ull MOD = 1000000007LL;



int n;

char s[100005];

ull dp[100005][13];

ull solve () {

int i, j, ki;

ull res = 0;



 scanf("%s", s);

 n = strlen(s);



 dp[0][0] = 1;

 for (i = 0; i < n; i++) {

 int c;

 if (s[i] == '?') c = -1;

 else c = s[i] - '0';



for (j = 0; j < 10; j++) {

 if (c != -1 && c != j) continue;

 for (ki = 0; ki < 13; ki++) {

 dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki];

 }

 }

 for (j = 0; j < 13; j++) dp[i + 1][j] %= MOD;

 }

 res = dp[n][5];



 printf("%llu\n", res);

 return 0;

 }



 int main()

 {

  solve();

  return 0;

 }


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define EPS (1e-7)

#define INF (1 << 30)

#define LLINF (1LL << 60)

#define PI (acos(-1))

#define MOD (1000000007)

#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};



//-------------------------------------



ll dp[100010][13];



ll m[100010];



void f(ll n)

{

    m[0] = 1;

    for (ll i = 0; i <= n; i++)

    {

        m[i + 1] = (m[i] * 10) % 13;

    }

}



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    string s;

    cin >> s;

    ll n = s.size();

    f(100005);

    dp[0][0] = 1LL;

    for (ll i = n - 1; i >= 0; i--)

    {

        ll it = n - i - 1;

        for (ll j = 0; j < 13; j++)

        {

            if (s[i] == '?')

            {

                for (ll num = 0; num < 10; num++)

                {

                    ll amari = (j + (num * m[it]) % 13) % 13;

                    (dp[it + 1][amari] += dp[it][j]) %= MOD;

                }

            }

            else

            {

                ll num = s[i] - '0';

                ll amari = (j + (num * m[it]) % 13) % 13;

                (dp[it + 1][amari] += dp[it][j]) %= MOD;

            }

        }

    }

    cout << dp[n][5] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

template <class T>

inline bool chmax(T &a, T b)

{

    if (a < b)

    {

        a = b;

        return 1;

    }

    return 0;

}

template <class T>

inline bool chmin(T &a, T b)

{

    if (a > b)

    {

        a = b;

        return 1;

    }

    return 0;

}

typedef long long int ll;



#define EPS (1e-7)

#define INF (1 << 30)

#define LLINF (1LL << 60)

#define PI (acos(-1))

#define MOD (1000000007)

#define ALL(v) (v).begin(), (v).end()

#define RALL(v) (v).rbegin(), (v).rend()

const int dx[4] = {1, 0, -1, 0};

const int dy[4] = {0, 1, 0, -1};



//-------------------------------------



ll dp[100010][13];



int main()

{

    cin.tie(0);

    ios::sync_with_stdio(false);

    string s;

    cin >> s;

    ll n = s.size();

    dp[0][0] = 1;

    for (ll i = 0; i < n; i++)

    {

        for (ll j = 0; j < 13; j++)

        {

            if (s[i] == '?')

            {

                for (ll k = 0; k < 10; k++)

                {

                    (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;

                }

            }

            else

            {

                ll k = s[i] - '0';

                (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;

            }

        }

    }

    cout << dp[n][5] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9+7;

const int MAX_N = 100100;

const int D = 13;

template<int mod> struct ModInt {

    int x;

    ModInt() : x(0) {}

    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }

    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }

    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }

    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{

        int a = x, b = mod, u = 1, v = 0, t;

        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }

        return ModInt(u);

    }

    ModInt pow(int e){

        long long a = 1, p = x;

        while (e > 0) {

            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}

            else {a = (a*p) % mod; e--;}

        }

        return ModInt(a);

    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {

        return os << p.x;

    }

    friend istream &operator>>(istream &is, ModInt<mod> &a) {

        long long x;

        is >> x;

        a = ModInt<mod>(x);

        return (is);

    }

};



int main() {

    string s;

    cin >> s;

    int n = s.length();

    ModInt<MOD> dp[MAX_N][D];

    dp[0][0] = 1;

    

    for (int i = 0; i < n; i++) {

        const int c = (s[i] == '?' ? -1 : s[i] - '0');

        for (int k = 0; k < 10; k++) {

            if (c != -1 && c != k) continue;

            for (int d = 0; d < D; d++) {

                dp[i+1][(k+10*d)%D] += dp[i][d];

            }

        }

    }

    

    cout << dp[n][5] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



constexpr int MOD = 1'000'000'007; //'



int main() {

    string s;

    cin >> s;



    const int n = s.length();

    vector<vector<int>> dp(n + 1, vector<int>(13, 0));

    dp[0][0] = 1;



    for (int i = 0; i < n; i++) {

        const int d = (s[i] == '?' ? -1 : s[i] - '0');

        for (int j = 0; j < 10; j++) {

            for (int k = 0; k < 13; k++) {

                if (d == -1 or d == j) {

                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];

                    dp[i + 1][(k * 10 + j) % 13] %= MOD;

                }

            }

        }

    }



    cout << dp[n][5] << '\n';



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;



//a^n (mod m)

const long long mod = 13;

long long modpow(long long a, long long n) {

    long long res = 1;

    while (n > 0) {

        if (n & 1) res = res * a % mod;

        a = a * a % mod;

        n >>= 1;

    }

    return res;

}



//mod mでの a の逆元を求める

long long modinv(long long a) {

    long long b = mod, u = 1, v = 0;

    while (b) {

        long long t = a / b;

        a -= t * b; swap(a, b);

        u -= t * v; swap(u, v);

    }

    u %= mod; 

    if (u < 0) u += mod;

    return u;

}



signed main(){

    ios::sync_with_stdio(false);

	cin.tie(0);

 

    string s;

    cin>>s;



    ll md=1e9+7;



    int n=s.size();

    ll dp[n+1][13]={};

    dp[0][0]=1;

    ll p[111111]={};



    for(int i=0;i<n;i++){

        p[i] = modpow(10,i);

    }



    reverse(s.begin(),s.end());



    for(int i=0;i<n;i++){

        for(int j=0;j<13;j++){

            if(s[i]=='?'){

                for(int k=0;k<=9;k++){

                    dp[i+1][j] += dp[i][(1300000000 + j - k*p[i])%13];

                    dp[i+1][j]%=md;

                }

            }

            else {

                dp[i+1][j] += dp[i][(1300000000 + j - (ll)(s[i]-'0')*p[i])%13];

                dp[i+1][j]%=md;

            }

        }

    }

    cout<<dp[n][5]<<endl;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;





signed main(){

    ios::sync_with_stdio(false);

	cin.tie(0);

 

    string s;

    cin>>s;



    ll MOD=1e9+7;



    int n=s.size();

    ll dp[n+1][13]={};

    dp[0][0]=1;





    for(int i=0;i<n;i++){

        for(int j=0;j<13;j++){

            if(s[i]=='?'){

                for(int k=0;k<=9;k++){

                    int next = (j*10+k)%13;

                    dp[i+1][next] += dp[i][j];

                    dp[i+1][next]%=MOD;

                }

            }

            else {

                int next = (j*10+s[i]-'0')%13;

                dp[i+1][next] += dp[i][j];

                dp[i+1][next]%=MOD;

            }

        }

    }

    cout<<dp[n][5]<<endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;



//a^n (mod m)

const long long mod = 13;

long long modpow(long long a, long long n) {

    long long res = 1;

    while (n > 0) {

        if (n & 1) res = res * a % mod;

        a = a * a % mod;

        n >>= 1;

    }

    return res;

}



//mod mでの a の逆元を求める

long long modinv(long long a) {

    long long b = mod, u = 1, v = 0;

    while (b) {

        long long t = a / b;

        a -= t * b; swap(a, b);

        u -= t * v; swap(u, v);

    }

    u %= mod; 

    if (u < 0) u += mod;

    return u;

}



signed main(){

    ios::sync_with_stdio(false);

	cin.tie(0);

 

    string s;

    cin>>s;



    ll MOD=1e9+7;



    int n=s.size();

    ll dp[n+1][13]={};

    dp[0][0]=1;

    ll p[111111]={};



    for(int i=0;i<n;i++){

        p[i] = modpow(10,i);

    }



    reverse(s.begin(),s.end());



    for(int i=0;i<n;i++){

        for(int j=0;j<13;j++){

            if(s[i]=='?'){

                for(int k=0;k<=9;k++){

                    int next = (j+k*p[i])%13;

                    dp[i+1][next] += dp[i][j];

                    dp[i+1][next]%=MOD;

                }

            }

            else {

                int next = (j+(s[i]-'0')*p[i])%13;

                dp[i+1][next] += dp[i][j];

                dp[i+1][next]%=MOD;

            }

        }

    }

    cout<<dp[n][5]<<endl;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;





signed main(){

    ios::sync_with_stdio(false);

	cin.tie(0);

 

    string s;

    cin>>s;



    ll MOD=1e9+7;



    int n=s.size();

    ll dp[n+1][13]={};

    dp[0][0]=1;





    for(int i=0;i<n;i++){

        for(int j=0;j<13;j++){

            if(s[i]=='?'){

                for(int k=0;k<=9;k++){

                    int next = (j*10+k)%13;

                    dp[i+1][next] += dp[i][j];

                    dp[i+1][next]%=MOD;

                }

            }

            else {

                int next = (j*10+s[i]-'0')%13;

                dp[i+1][next] += dp[i][j];

                dp[i+1][next]%=MOD;

            }

        }

    }

    cout<<dp[n][5]<<endl;

}


// Fastest known solution for this problem: