stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



using i32 = std::int_fast32_t;

using i64 = std::int_fast64_t;



#define REP(i, stop) FOR(i, 0, stop)

#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)

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



struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;



i64 dp[100010][13];

const i64 M = 1000000007;

signed main() {

	string S;

	cin >> S;

	i64 k = 0;

	dp[0][0] = 1;

	REP(i, S.size()) {

		char c = S[i];

		if (c == '?') {

			REP(r, 13) {

				i64 s = 0;

				REP(j, 10) {

					s += dp[k][(j - r + 13) * 9 % 13];

				}

				dp[k + 1][r] = s % M;

			}

		} else {

			i64 d = c - '0';

			REP(r, 13) {

				i64 s = dp[k][(d - r + 13) * 9 % 13];

				dp[k + 1][r] = s % M;

			}

		}

		k += 1;

	}

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

}


// Faster C++ solution for the same problem (measured speedup: 5.2957805659235095x):
#include <cstdio>

#include <utility>

using namespace std;



using i64 = long long;



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



i64 D[13];

i64 E[13];

char S[100001];

const i64 M = 1000000007;

signed main() {

	D[0] = 1;

	scanf("%s", S);

	i64 i = 0;

	while(true) {

		char c = S[i];

		if (c == 0) {

			break;

		} else if (c == '?') {

			/*

			REP(r, 13) {

				i64 s = 0;

				REP(j, 10) {

					s += D[(j - r + 13) * 9 % 13];

				}

				E[r] = s % M;

			}

			*/

			i64 s = D[0] + D[1] + D[2] + D[3] + D[4] + D[5] + D[6] + D[7] + D[8] + D[9] + D[10] + D[11] + D[12];

			E[0] = (s - D[4] - D[8] - D[12]) % M;

			E[1] = (s - D[3] - D[8] - D[12]) % M;

			E[2] = (s - D[3] - D[7] - D[12]) % M;

			E[3] = (s - D[3] - D[7] - D[11]) % M;

			E[4] = (s - D[2] - D[7] - D[11]) % M;

			E[5] = (s - D[2] - D[6] - D[11]) % M;

			E[6] = (s - D[2] - D[6] - D[10]) % M;

			E[7] = (s - D[1] - D[6] - D[10]) % M;

			E[8] = (s - D[1] - D[5] - D[10]) % M;

			E[9] = (s - D[1] - D[5] - D[9]) % M;

			E[10] = (s - D[0] - D[5] - D[9]) % M;

			E[11] = (s - D[0] - D[4] - D[9]) % M;

			E[12] = (s - D[0] - D[4] - D[8]) % M;

		} else {

			i64 d = c - '0';

			/*

			REP(r, 13) {

				E[r] = D[(d - r + 13) * 9 % 13];

			}

			*/

			E[d] = D[0];

			E[(d + 10) % 13] = D[1];

			E[(d + 7) % 13] = D[2];

			E[(d + 4) % 13] = D[3];

			E[(d + 1) % 13] = D[4];

			E[(d + 11) % 13] = D[5];

			E[(d + 8) % 13] = D[6];

			E[(d + 5) % 13] = D[7];

			E[(d + 2) % 13] = D[8];

			E[(d + 12) % 13] = D[9];

			E[(d + 9) % 13] = D[10];

			E[(d + 6) % 13] = D[11];

			E[(d + 3) % 13] = D[12];

		}

		swap(D, E);

		++i;

	}

	printf("%d", D[5]);

}
// Slower C++ solution:
#include <bits/stdc++.h>

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

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

#define fi first

#define se second

#define pb push_back

#define read(type, ...)type __VA_ARGS__; macro_scan(__VA_ARGS__);



using namespace std;



template<typename T> void macro_scan(T& t){cin>>t;};

template<typename F, typename ...R>void macro_scan(F& f , R& ...r){

  cin>>f;macro_scan(r...);

}



void deb(){

    cerr<<endl;

}

template<typename T , typename... t>

void deb(T a , t...b){

    cerr<<a<<" ";

    deb(b...);

}

template<typename T>

void dev(vector<T>v){

    int c = 0;

    for(auto i : v){

        cerr<<i<<" ";

        c++;

    }

    cerr<<endl;

}

const int N = 1e5 + 2;

const int M = 1e9 + 7;

string s;

int dp[N][13];





void add_self(int &a , int b , int Mod){

    a += b;

    if(a >= Mod){

        a -= Mod;

    }

}

int rec(int pos , int rem ){

    if(pos >= s.size())return rem%13 == 5;

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

    int ans  = 0;

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

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

            add_self(ans , rec(pos + 1 , (rem * 10 + i)%13) , M);

        }

    }else{

        add_self(ans , rec(pos + 1 , (rem * 10 + s[pos] - '0') % 13),M);

    }

    return dp[pos][rem] = ans;

}



int main(){

    ios_base::sync_with_stdio(0);

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

    //int t; cin>>t;for(;t--;)done();

    cin>>s;

    memset(dp , -1 , sizeof(dp));

    cout<<rec(0 , 0)<<"\n";





}






// Faster C++ solution for the same problem (measured speedup: 6.267668917022296x):
#include <bits/stdc++.h>

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

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

#define fi first

#define se second

#define pb push_back

#define read(type, ...)type __VA_ARGS__; macro_scan(__VA_ARGS__);



using namespace std;



template<typename T> void macro_scan(T& t){cin>>t;};

template<typename F, typename ...R>void macro_scan(F& f , R& ...r){

  cin>>f;macro_scan(r...);

}



void deb(){

    cerr<<endl;

}

template<typename T , typename... t>

void deb(T a , t...b){

    cerr<<a<<" ";

    deb(b...);

}

template<typename T>

void dev(vector<T>v){

    int c = 0;

    for(auto i : v){

        cerr<<i<<" ";

        c++;

    }

    cerr<<endl;

}

const int N = 1e5 + 2;

const int M = 1e9 + 7;

string s;

int dp[N][13];





void add_self(int &a , int b , int Mod){

    a += b;

    if(a >= Mod){

        a -= Mod;

    }

}





int main(){

    ios_base::sync_with_stdio(0);

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

    //int t; cin>>t;for(;t--;)done();

    cin>>s;

    int n = s.size();

    dp[0][0] = 1;

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

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

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

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

                   add_self( dp[i][(j * 10 + k)%13] , dp[i - 1][j] , M);

                }

            }else{

                add_self(dp[i][(j*10 + s[i - 1] - '0')%13] , dp[i - 1][j] , M);

            }

        }

    }

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



}
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

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

#define pb push_back

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

#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

const double EPS = 1e-9;



signed main(){

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  string S;

  cin >> S;

  

  vector<int> dp(13);

  dp[0] = 1;



  for (auto c: S) {

    vector<int> dp_nxt(13);

    REP(i, 10) if (c == '?' || c == (char)('0' + i)) {

      REP(d, 13) (dp_nxt[(d * 10 + i) % 13] += dp[d]) %= MOD;

    }

    dp = dp_nxt;

  }

  

  cout << dp[5] << endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.174104046374243x):
#include <stdio.h>

#include <string.h>

static const long long MOD = 1000000007LL;

int n;

char s[100005];

long long unsigned int dp[100005][13];

int main () {

int i, j, ki;

long long unsigned int 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;

 }
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

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

#define pb push_back

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

#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

const double EPS = 1e-9;



signed main(){

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  string S;

  cin >> S;

  

  vector<int> dp(13);

  dp[0] = 1;



  for (auto c: S) {

    vector<int> dp_nxt(13);

    REP(i, 10) if (c == '?' || c == (char)('0' + i)) {

      REP(d, 13) (dp_nxt[(d * 10 + i) % 13] += dp[d]) %= MOD;

    }

    dp = dp_nxt;

  }

  

  cout << dp[5] << endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.174104046374243x):
#include <stdio.h>

#include <string.h>

static const long long MOD = 1000000007LL;

int n;

char s[100005];

long long unsigned int dp[100005][13];

int main () {

  int i, j, ki;

  long long unsigned int 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;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

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

#define pb push_back

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

#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;

const int MOD = 1000000007;

const double EPS = 1e-9;



signed main(){

  cin.tie(nullptr);

  ios::sync_with_stdio(false);



  string S;

  cin >> S;

  int n = S.length();



  vector<int> dp(13);

  dp[0] = 1;

  

  REP(i, n) {

    vector<int> dp_nxt(13);

    int c;

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

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



    REP(j, 10) {

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

      REP(ki, 13) {

        (dp_nxt[(ki * 10 + j) % 13] += dp[ki]) %= MOD;

      }

    }

    dp = dp_nxt;

  }



  cout << dp[5] << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.174893553527186x):
#include <stdio.h>

#include <string.h>

static const long long MOD = 1000000007LL;

int n;

char s[100005];

long long unsigned int dp[100005][13];

int main () {

  int i, j, ki;

  long long unsigned int 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;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



string s;

int mod = 1e9 + 7;

int mem[100005][15];

int fact[100005];



int solve(int ind, int rem){

    if(ind == s.size()) return rem == 5;

    int &ret = mem[ind][rem];

    if(~ret) return ret;

    ret = 0;

    if(s[ind] != '?')

        return ret = solve(ind+1, (rem + fact[ind] * (s[ind]-'0')) % 13);



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

        ret += solve(ind + 1, (rem + fact[ind] * i) % 13);

        ret %= mod;

    }

    return ret;

}





int main() {

#ifndef ONLINE_JUDGE

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

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

#endif

    cin >> s;

    memset(mem, -1, sizeof(mem));

    fact[s.size()-1] = 1;

    for(int i=(int)s.size()-2; i>=0; i--){

        fact[i] = fact[i+1] * 10;

        fact[i] %= 13;

    }

    printf("%d", solve(0, 0));

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 7.108577333486378x):
#include <bits/stdc++.h>



using namespace std;

const int N = 1e5+5;

const int MOD = 1e9+7;

long long dp[N][15];

int main()

{

    string s;

    cin >> s;

    int n = s.length();

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

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

            dp[0][i] = 1;

    else

        dp[0][s[0]-'0'] = 1;

    for (int i = 1; i<n; i++)

    {

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

        {

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

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

                {

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

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

                }

        }

        else

        {

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

            {

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

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

            }

        }

    }

    cout << dp[n-1][5];

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



string s;

int mod = 1e9 + 7;

int mem[100005][15];

int fact[100005];



int solve(int ind, int rem){

    if(ind == s.size()) return rem == 5;

    int &ret = mem[ind][rem];

    if(~ret) return ret;

    ret = 0;

    if(s[ind] != '?')

        return ret = solve(ind+1, (rem + fact[ind] * (s[ind]-'0')) % 13);



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

        ret += solve(ind + 1, (rem + fact[ind] * i) % 13);

        ret %= mod;

    }

    return ret;

}





int main() {

#ifndef ONLINE_JUDGE

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

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

#endif

    cin >> s;

    memset(mem, -1, sizeof(mem));

    fact[s.size()-1] = 1;

    for(int i=(int)s.size()-2; i>=0; i--){

        fact[i] = fact[i+1] * 10;

        fact[i] %= 13;

    }

    printf("%d", solve(0, 0));

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 37.62279217754516x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

const int N = 1e5+5;

const int MOD = 1e9+7;

long long dp[N][15];

int main()

{

    string s;

    cin >> s;

    int n = s.length();

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

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

            dp[0][i] = 1;

    else

        dp[0][s[0]-'0'] = 1;

    for (int i = 1; i<n; i++)

    {

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

        {

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

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

                {

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

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

                }

        }

        else

        {

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

            {

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

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

            }

        }

    }

    cout << dp[n-1][5];

}


// Faster C++ solution for the same problem (measured speedup: 5.292590966172016x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 62.331578380430265x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 1.134231957329587x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 11.525536528758979x):
#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;

}