Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <algorithm> // sort
#include <cmath>
#include <cstring>
#include <iostream>
#include <map> // pair
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
const ll mod = 1e9 + 7;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll amari_pow[(int)2e5];
void func() {
  amari_pow[0] = 1;
  REP(i, 1, (int)1e5 + 7) { amari_pow[i] = amari_pow[i - 1] * 10 % 13; }
}
int main() {
  string s;
  cin >> s;
  ll length = s.size();
  ll ans[100][13];
  memset(ans, 0, sizeof(ans));
  func();
  ll sum = 0;
  ans[0][0] = 1;
  rep(i, length) {
    if (s[i] == '?') {
      rep(j, 13) {
        rep(k, 10) {
          ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] += ans[i][j];
          ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] %= mod;
        }
      }
    } else {
      rep(j, 13) {
        ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] =
            ans[i][j];
        ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] %= mod;
      }
    }
  }
  // rep(i,length+1){
  //   rep(j,13){
  //     cout << ans[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  cout << ans[length][5];
}


Fixed submission:
#include <algorithm>
#include <algorithm> // sort
#include <cmath>
#include <cstring>
#include <iostream>
#include <map> // pair
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
const ll mod = 1e9 + 7;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll amari_pow[(int)2e5];
void func() {
  amari_pow[0] = 1;
  REP(i, 1, (int)1e5 + 7) { amari_pow[i] = amari_pow[i - 1] * 10 % 13; }
}
int main() {
  string s;
  cin >> s;
  ll length = s.size();
  ll ans[(int)2e5][13];
  memset(ans, 0, sizeof(ans));
  func();
  ll sum = 0;
  ans[0][0] = 1;
  rep(i, length) {
    if (s[i] == '?') {
      rep(j, 13) {
        rep(k, 10) {
          ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] += ans[i][j];
          ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] %= mod;
        }
      }
    } else {
      rep(j, 13) {
        ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] =
            ans[i][j];
        ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] %= mod;
      }
    }
  }
  // rep(i,length+1){
  //   rep(j,13){
  //     cout << ans[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  cout << ans[length][5];
}