stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;



}


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



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

}

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

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

}

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

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

}

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

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

}

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

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

}


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

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<string>

#include<cmath>

#include<cstdio>

#include<queue>

#include<deque>

#include<map>

#include<stack>

#include<set>

#include<utility>

using namespace std;

typedef pair<int,int> ii;

typedef long long ll;

typedef pair<ll,ll> p;

typedef unsigned long long int ull;

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

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

const int MAXN=100000;

const int MAXE=100000;

const int MAXV=10000;

const ll INF=2e18;

ll MOD=1e9+7;



ll power(ll a,ll x){

    ll res=1;

  while(x>0){

    if(x&1) res=res*a%13;

    a=a*a%13;

    x>>=1;

  }

    return res;

}



int main(){

    string s;cin>>s;

    int n=(int)s.size();

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

    dp[n][0]=1;

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

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

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

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

                    dp[i-1][(d*power(10,n-i)+j)%13]+=dp[i][j];

                    dp[i-1][(d*power(10,n-i)+j)%13]%=MOD;

                }

            }else{

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

                dp[i-1][(d*power(10,n-i)+j)%13]+=dp[i][j];

                dp[i-1][(d*power(10,n-i)+j)%13]%=MOD;

            }

        }

    }

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

    return 0;

}

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

#include<algorithm>

#include<vector>

#include<string>

#include<cmath>

#include<cstdio>

#include<queue>

#include<deque>

#include<map>

#include<stack>

#include<set>

#include<utility>

using namespace std;

typedef pair<int,int> ii;

typedef long long ll;

typedef pair<ll,ll> p;

typedef unsigned long long int ull;

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

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

const int MAXN=100000;

const int MAXE=100000;

const int MAXV=10000;

const ll INF=2e18;

ll MOD=1e9+7;



ll power(ll a,ll x){

    ll res=1;

    while(x>0){

        if(x&1) res=res*a%13;

        a=a*a%13;

        x>>=1;

    }

    return res;

}



int main(){

    string s;cin>>s;

    int n=(int)s.size();

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

    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<10;k++){

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

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

                }

            }else{

                int k=(int)(s[i]-'0');

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

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

            }

        }

    }

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

    return 0;

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

#define ft first

#define sc second

#define pt(sth) cout << sth << "\n"

#define chmax(a, b) {if(a<b) a=b;}

#define chmin(a, b) {if(a>b) a=b;}

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

static const ll INF=1e18;

static const ll MAX=1e5+7;

static ll MOD=1e9+7;

ll max(ll a, ll b) {return a>b?a:b;}

ll min(ll a, ll b) {return a<b?a:b;}





ll ten(ll n) {

  ll res=1;

  ll x=10;

  while(n>0) {

    if(n&1) res=res*x%13;

    x=x*x%13;

    n>>=1;

  }

  return res;

}



ll dp[MAX][13]={};

int main(void) {

  string s;

  cin >> s;

  ll i, j, k;

  ll N=s.size();

  

  dp[0][0]=1;

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

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

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

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

          moC(dp[i+1][(j+k*ten(N-i-1))%13], +, dp[i][j]);

        }

      }else {

        moC(dp[i+1][(j+(s[i]-'0')*ten(N-i-1))%13], +, dp[i][j]);

      }

    }

  }

  

  pt(dp[N][5]);

}


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

#define pt(sth) cout << sth << "\n"

#define chmax(a, b) {if(a<b) a=b;}

#define chmin(a, b) {if(a>b) a=b;}

#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

static const ll INF=1e18;

static const ll MAX=101010;

static const ll MOD=1e9+7;

static const ll LOGN=55;





ll dp[MAX][15]={};



int main(void) {

  string s;

  cin >> s;

  ll N=(ll)s.size();

  ll i, j, k;

  

  dp[0][0]=1;

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

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

      

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

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

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

      else

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

      

    }

  }

  

  pt(dp[N][5]);

  

  

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



using namespace std;

const int N = 1e5 + 3, MOD = 1e9 + 7;

char s[N];

int mem[N][13];

int go(int i, int m) {

	if (!s[i])

		return m == 5;

	int &ret = mem[i][m];

	if (~ret)

		return ret;

	ret = 0;

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

		for (int d = 0; d <= 9; ++d)

			ret = (ret + go(i + 1, (m * 10 + d) % 13)) % MOD;

	else

		ret = go(i + 1, (m * 10 + s[i] - '0') % 13);

	return ret;

}

int main() {

#ifndef ONLINE_JUDGE

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

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

#endif

	scanf("%s", s);

	memset(mem, -1, sizeof mem);

	printf("%d\n", go(0, 0));

	return 0;

}

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

using namespace std;



const int mxn = 1e5 + 5;

const long long mod = 1e9 + 7;



long long dp[mxn][15];



int main() {

    string s;

    cin >> s;

    dp[int(s.size())][0] = 1;

    for (int i = int(s.size()) - 1, ex = 1; i >= 0; i--) {

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

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

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

                    dp[i][(c * ex + t) % 13] += dp[i + 1][t];

                    dp[i][(c * ex + t) % 13] %= mod;

                }

            }

        } else {

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

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

                dp[i][(c * ex + t) % 13] = dp[i + 1][t];

            }

        }

        ex = (ex * 10) % 13;

    }

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

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



using namespace std;



const int N = 1e5 + 5 , MOD = 1e9 + 7;

int p[N] , memo[N][14];

string s;



int mul(int a , int b , int m) {

    return a * 1ll * b % m;

}



int add(int a , int b , int m) {

    a += b;

    while (a >= m) a -= m;

    while (a < 0) a += m;

    return a;

}



int solve (int i , int m) {

    if (i == s.size())

        return m == 5;



    int &ret = memo[i][m];

    if (~ret)

        return ret;



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

        return ret = solve(i + 1 , add(m , mul(s[i] , p[s.size() - i - 1] , 13) , 13));



    ret = 0;



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

        ret = add(ret , solve(i + 1 , add(m , mul(j , p[s.size() - i - 1] , 13) , 13)) , MOD);



    return ret;

}



int main() {

    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);



    p[0] = 1;

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

        p[i] = p[i - 1] * 10 % 13;



    cin >> s;

    for (char &c : s) if (c != '?') c -= '0';

    memset(memo , -1 , sizeof memo);

    cout << solve(0 , 0);

}

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

using namespace std;



const int mxn = 1e5 + 5;

const long long mod = 1e9 + 7;



long long dp[mxn][15];



int main() {

    string s;

    cin >> s;

    dp[int(s.size())][0] = 1;

    for (int i = int(s.size()) - 1, ex = 1; i >= 0; i--) {

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

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

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

                    dp[i][(c * ex + t) % 13] += dp[i + 1][t];

                    dp[i][(c * ex + t) % 13] %= mod;

                }

            }

        } else {

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

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

                dp[i][(c * ex + t) % 13] = dp[i + 1][t];

            }

        }

        ex = (ex * 10) % 13;

    }

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

}