prithivMLmods/Coder-Stat huggingface dataset:
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

const int Inf = 1e9 + 7;
const double EPS = 1e-9;
const int n = 13;

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

int bitCount(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int len = s.size();
  int dp[len][n];
  rep(i, len) { rep(j, n) dp[i][j] = 0; }

  dp[0][0] = 1;
  int mal = 1;
  for (int i = len - 1; i >= 0; --i) {
    int index = len - i;
    if (s[i] == '?') {
      rep(j, n) {
        rep(k, 10) {
          dp[index][(j + k * mal) % n] += dp[index - 1][j];
          dp[index][(j + k * mal) % n] %= Inf;
        }
      }
    } else {
      int num = s[i] - '0';
      rep(j, n) {
        dp[index][(j + num * mal) % n] += dp[index - 1][j];
        dp[index][(j + num * mal) % n] %= Inf;
      }
    }
    mal *= 10;
    mal %= n;
  }
  cout << dp[len][5] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

const int Inf = 1e9 + 7;
const double EPS = 1e-9;
const int n = 13;

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

int bitCount(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int len = s.size();
  int dp[len + 1][n];
  rep(i, len + 1) { rep(j, n) dp[i][j] = 0; }

  dp[0][0] = 1;
  int mal = 1;
  for (int i = len - 1; i >= 0; --i) {
    int index = len - i;
    if (s[i] == '?') {
      rep(j, n) {
        rep(k, 10) {
          dp[index][(j + k * mal) % n] += dp[index - 1][j];
          dp[index][(j + k * mal) % n] %= Inf;
        }
      }
    } else {
      int num = s[i] - '0';
      rep(j, n) {
        dp[index][(j + num * mal) % n] += dp[index - 1][j];
        dp[index][(j + num * mal) % n] %= Inf;
      }
    }
    mal *= 10;
    mal %= n;
  }
  cout << dp[len][5] << endl;

  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
string s;
ll dp[10005][15];
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  int n = s.length();
  s = "*" + s;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k <= 9; k++) {
          (dp[i][(j * 10 + k) % 13] += dp[i - 1][j]) %= mod;
        }
      }
    } else {
      int p = s[i] - '0';
      for (int j = 0; j < 13; j++) {
        dp[i][(j * 10 + p) % 13] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][5] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
string s;
ll dp[100005][15];
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  int n = s.length();
  s = "*" + s;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '?') {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k <= 9; k++) {
          (dp[i][(j * 10 + k) % 13] += dp[i - 1][j]) %= mod;
        }
      }
    } else {
      int p = s[i] - '0';
      for (int j = 0; j < 13; j++) {
        dp[i][(j * 10 + p) % 13] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using ll = long long;

using namespace std;
ll MOD = 1000000000 + 7;
ll c[100050][13];
int initCount() {
  for (ll yi = 0; yi < 100050; yi++) {
    for (ll xi = 0; xi < 13; xi++) {
      c[yi][xi] = -1;
    }
  }
}

ll solve(ll y, ll x, string s) {
  if (c[y][x] != -1) {
    return c[y][x];
  }
  if (s[y] != '?') {
    // 全部の値を更新
    int tmp = s[y] - '0';
    for (ll xi = 0; xi < 13; xi++) {
      c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD;
    }
    return c[y][x];
  }
  // はてなの時の処理
  for (int tmp = 0; tmp < 10; tmp++) {
    for (ll xi = 0; xi < 13; xi++) {
      if (tmp == 0) {
        c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD;
      } else {
        c[y][(xi * 10 + tmp) % 13] += solve(y - 1, xi, s) % MOD;
      }
    }
  }
  return c[y][x];
}

int main() {
  string s;
  cin >> s;
  initCount();
  for (ll xi = 0; xi < 13; xi++) {
    c[0][xi] = 0;
  }
  if (s[0] != '?') {
    c[0][s[0] - '0'] = 1;
  } else {
    for (int i = 0; i < 10; i++) {
      c[0][i] = 1;
    }
  }
  ll ans = solve(s.size() - 1, 5, s) % MOD;
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using ll = long long;

using namespace std;
ll MOD = 1000000000 + 7;
ll c[100050][13];
int initCount() {
  for (ll yi = 0; yi < 100050; yi++) {
    for (ll xi = 0; xi < 13; xi++) {
      c[yi][xi] = -1;
    }
  }
}

ll solve(ll y, ll x, string &s) {
  if (c[y][x] != -1) {
    return c[y][x];
  }
  if (s[y] != '?') {
    // 全部の値を更新
    int tmp = s[y] - '0';
    for (ll xi = 0; xi < 13; xi++) {
      c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD;
    }
    return c[y][x];
  }
  // はてなの時の処理
  for (int tmp = 0; tmp < 10; tmp++) {
    for (ll xi = 0; xi < 13; xi++) {
      if (tmp == 0) {
        c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD;
      } else {
        c[y][(xi * 10 + tmp) % 13] += solve(y - 1, xi, s) % MOD;
      }
    }
  }
  return c[y][x];
}

int main() {
  string s;
  cin >> s;
  initCount();
  for (ll xi = 0; xi < 13; xi++) {
    c[0][xi] = 0;
  }
  if (s[0] != '?') {
    c[0][s[0] - '0'] = 1;
  } else {
    for (int i = 0; i < 10; i++) {
      c[0][i] = 1;
    }
  }
  ll ans = solve(s.size() - 1, 5, s) % MOD;
  cout << ans << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  vector<vector<ll>> dp(100000, vector<ll>(13));
  int l, i, j, k;
  string S;
  cin >> S;
  l = S.size();

  dp.at(0).at(0) = 1;
  for (i = 0; i < l; i++) {
    int c;
    if (S.at(i) == '?')
      c = -1;
    else
      c = S.at(i) - '0';

    for (j = 0; j < 10; j++)
      if (c == -1 || c == j)
        for (k = 0; k < 13; k++)
          dp.at(i + 1).at((k * 10 + j) % 13) += dp.at(i).at(k);

    for (j = 0; j < 13; j++)
      dp.at(i + 1).at(j) %= mod;
  }

  cout << dp.at(l).at(5) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  vector<vector<ll>> dp(100005, vector<ll>(13, 0));
  int l, i, j, k;
  string S;
  cin >> S;
  l = S.size();

  dp.at(0).at(0) = 1;
  for (i = 0; i < l; i++) {
    int c;
    if (S.at(i) == '?')
      c = -1;
    else
      c = S.at(i) - '0';

    for (j = 0; j < 10; j++)
      if (c == -1 || c == j)
        for (k = 0; k < 13; k++)
          dp.at(i + 1).at((k * 10 + j) % 13) += dp.at(i).at(k);

    for (j = 0; j < 13; j++)
      dp.at(i + 1).at(j) %= mod;
  }

  cout << dp.at(l).at(5) << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int m = 1e9 + 7;
vector<int> v;
int p[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int a[100000][13], r;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      v.push_back(s.size() - i - 1);
    else {
      r = (r + (s[i] - '0') * p[(s.size() - i - 1) % 6]) % 13;
    }
  }
  r = (18 - r) % 13;
  a[0][0] = 1;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < 13; j++)
      for (int k = 0; k < 10; k++) {
        a[i + 1][(j + k * p[v[i] % 6]) % 13] += a[i][j];
        a[i + 1][(j + k * p[v[i] % 6]) % 13] %= m;
      }
  }
  cout << a[v.size()][r] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int m = 1e9 + 7;
vector<int> v;
int p[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int a[100001][13], r;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      v.push_back(s.size() - i - 1);
    else {
      r = (r + (s[i] - '0') * p[(s.size() - i - 1) % 6]) % 13;
    }
  }
  r = (18 - r) % 13;
  a[0][0] = 1;
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < 13; j++)
      for (int k = 0; k < 10; k++) {
        a[i + 1][(j + k * p[v[i] % 6]) % 13] += a[i][j];
        a[i + 1][(j + k * p[v[i] % 6]) % 13] %= m;
      }
  }
  cout << a[v.size()][r] << endl;
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n)                                                               \
  rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int, P>
#define PP pair<P, P>

string s;
int dp[10010][20];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> s;
  dp[0][0] = 1;
  rep(i, s.size()) {
    int c;
    if (s[i] == '?')
      c = -1;
    else
      c = s[i] - '0';
    rep(j, 13) {
      rep(k, 10) {
        if (c != -1 && c != k)
          continue;
        dp[i + 1][(10 * j + k) % 13] += dp[i][j];
        dp[i + 1][(10 * j + k) % 13] %= M;
      }
    }
  }

  cout << dp[s.size()][5] << endl;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n)                                                               \
  rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int, P>
#define PP pair<P, P>

string s;
int dp[100100][20];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  cin >> s;
  dp[0][0] = 1;
  rep(i, s.size()) {
    int c;
    if (s[i] == '?')
      c = -1;
    else
      c = s[i] - '0';
    rep(j, 13) {
      rep(k, 10) {
        if (c != -1 && c != k)
          continue;
        dp[i + 1][(10 * j + k) % 13] += dp[i][j];
        dp[i + 1][(10 * j + k) % 13] %= M;
      }
    }
  }

  cout << dp[s.size()][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int MOD = 1000000007;
long long int POW(int n, int k, int m) {
  long long int r;
  if (k == 0)
    return 1;
  r = POW(n, k / 2, m) % m;
  r = (r * r) % m;
  if (k % 2)
    r = (n * r) % m;
  return r;
}
int main() {
  int N, ans[10000][13] = {0}, n, sur, pre;
  string S;
  cin >> S;
  N = S.length();
  for (int i = 0; i < N; i++) {
    sur = POW(10, N - i - 1, 13);
    if (S[i] == '?') {
      if (i >= 1) {
        for (int j = 0; j < 13; j++) {
          for (int k = 0; k < 10; k++) {
            pre = (sur * k) % 13;
            ans[i][(j + pre) % 13] += ans[i - 1][j];
            ans[i][(j + pre) % 13] %= MOD;
          }
        }
      } else {
        for (int k = 0; k < 10; k++)
          ans[i][(sur * k) % 13] += 1;
      }
    } else {
      n = S[i] - '0';
      sur = (sur * n) % 13;
      if (i >= 1) {
        for (int j = 0; j < 13; j++)
          ans[i][(j + sur) % 13] = ans[i - 1][j];
      } else {
        ans[i][sur] = 1;
      }
    }
  }
  cout << ans[N - 1][5];
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int MOD = 1000000007;
long long int POW(int n, int k, int m) {
  long long int r;
  if (k == 0)
    return 1;
  r = POW(n, k / 2, m) % m;
  r = (r * r) % m;
  if (k % 2)
    r = (n * r) % m;
  return r;
}
int main() {
  int N, ans[100000][13] = {0}, n, sur, pre;
  string S;
  cin >> S;
  N = S.length();
  for (int i = 0; i < N; i++) {
    sur = POW(10, N - i - 1, 13);
    if (S[i] == '?') {
      if (i >= 1) {
        for (int j = 0; j < 13; j++) {
          for (int k = 0; k < 10; k++) {
            pre = (sur * k) % 13;
            ans[i][(j + pre) % 13] += ans[i - 1][j];
            ans[i][(j + pre) % 13] %= MOD;
          }
        }
      } else {
        for (int k = 0; k < 10; k++)
          ans[i][(sur * k) % 13] += 1;
      }
    } else {
      n = S[i] - '0';
      sur = (sur * n) % 13;
      if (i >= 1) {
        for (int j = 0; j < 13; j++)
          ans[i][(j + sur) % 13] = ans[i - 1][j];
      } else {
        ans[i][sur] = 1;
      }
    }
  }
  cout << ans[N - 1][5];
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
typedef long long ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  ll mod = 1e9 + 7, sum;
  ll n = s.size();
  ll dp[10000000][13];
  dp[0][0] = 1;

  for (ll i = 0; i < n; i++) {
    ll c = 0;
    if (s[i] == '?') {
      c = -1;
    } else {
      c = s[i] - '0';
    }
    for (ll j = 0; j < 10; j++) {

      if (c != -1 && c != j)
        continue;
      for (ll k = 0; k < 13; k++) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    for (ll j = 0; j < 13; j++)
      dp[i + 1][j] %= mod;
  }
  sum = dp[n][5];
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
typedef long long ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  ll mod = 1e9 + 7, sum;
  ll n = s.size();
  ll dp[1000000][13];
  dp[0][0] = 1;

  for (ll i = 0; i < n; i++) {
    ll c = 0;
    if (s[i] == '?') {
      c = -1;
    } else {
      c = s[i] - '0';
    }
    for (ll j = 0; j < 10; j++) {

      if (c != -1 && c != j)
        continue;
      for (ll k = 0; k < 13; k++) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    for (ll j = 0; j < 13; j++)
      dp[i + 1][j] %= mod;
  }
  sum = dp[n][5];
  cout << sum << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

ll dp[10010][13];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  dp[0][0] = 1;
  for (int i = 0; i < (int)S.size(); i++) {
    int c;
    if (S[i] == '?')
      c = -1;
    else
      c = S[i] - '0';
    for (int number_pos = 0; number_pos <= 9; number_pos++) {
      if (c != -1 && c != number_pos)
        continue;
      for (int mod_prev = 0; mod_prev < 13; mod_prev++) {
        int mod_pos = (mod_prev * 10 + number_pos) % 13;
        dp[i + 1][mod_pos] += dp[i][mod_prev];
        dp[i + 1][mod_pos] %= MOD;
      }
    }
  }

  cout << dp[(int)S.size()][5] << endl;
  return 0;
}


Fixed submission:
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

ll dp[100010][13];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  dp[0][0] = 1;
  for (int i = 0; i < (int)S.size(); i++) {
    int c;
    if (S[i] == '?')
      c = -1;
    else
      c = S[i] - '0';
    for (int number_pos = 0; number_pos <= 9; number_pos++) {
      if (c != -1 && c != number_pos)
        continue;
      for (int mod_prev = 0; mod_prev < 13; mod_prev++) {
        int mod_pos = (mod_prev * 10 + number_pos) % 13;
        dp[i + 1][mod_pos] += dp[i][mod_prev];
        dp[i + 1][mod_pos] %= MOD;
      }
    }
  }

  cout << dp[(int)S.size()][5] << endl;
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
using namespace std;

char S[100];
long long dp[100001][13];

int main() {
  map<char, int> m = {{'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
                      {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'?', -1}};
  scanf("%s", S);
  dp[0][0] += 1;

  rep(i, strlen(S)) {
    int n = m[S[i]];
    rep(j, 10) {
      if (n != -1 && n != j)
        continue;
      rep(ki, 13) { dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]; }
    }
    rep(j, 13) dp[i + 1][j] %= MOD;
  }
  cout << dp[strlen(S)][5] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
using namespace std;

char S[100001];
long long dp[100001][13];

int main() {
  map<char, int> m = {{'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
                      {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'?', -1}};
  scanf("%s", S);
  dp[0][0] += 1;

  rep(i, strlen(S)) {
    int n = m[S[i]];
    rep(j, 10) {
      if (n != -1 && n != j)
        continue;
      rep(ki, 13) { dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]; }
    }
    rep(j, 13) dp[i + 1][j] %= MOD;
  }
  cout << dp[strlen(S)][5] << endl;
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mode 1000000007
#define ll long long
char s[100001];
ll dp[10001][13]; // i代表前几个字符组成，j代表模13的余数
int main() {
  scanf("%s", s);
  int n = strlen(s);
  memset(dp, 0, sizeof(dp));
  if (s[0] == '?') {
    for (int i = 0; i < 10; i++)
      dp[0][i] = 1; // 1个字符组成的数字模13余数为i的个数
  } else
    dp[0][s[0] - '0'] = 1;
  // cout<<"sdf"<<endl;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 13; j++) // 遍历前一个状态的余数
    {
      if (s[i] != '?') {
        int y = j * 10 + (s[i] - '0');
        dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新
        continue; // 不用枚举0->9
      }

      for (int k = 0; k <= 9; k++) {
        int y = j * 10 + k;
        dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新
      }
    }
  }

  cout << dp[n - 1][5] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mode 1000000007
#define ll long long
char s[100010];
ll dp[100001][13]; // i代表前几个字符组成，j代表模13的余数
int main() {
  scanf("%s", s);
  int n = strlen(s);
  memset(dp, 0, sizeof(dp));
  if (s[0] == '?') {
    for (int i = 0; i < 10; i++)
      dp[0][i] = 1; // 1个字符组成的数字模13余数为i的个数
  } else
    dp[0][s[0] - '0'] = 1;
  // cout<<"sdf"<<endl;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 13; j++) // 遍历前一个状态的余数
    {
      if (s[i] != '?') {
        int y = j * 10 + (s[i] - '0');
        dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新
        continue; // 不用枚举0->9
      }

      for (int k = 0; k <= 9; k++) {
        int y = j * 10 + k;
        dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新
      }
    }
  }

  cout << dp[n - 1][5] << endl;
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MAX (int)1e+3
#define M 13
typedef long long ll;

char S[MAX];
static const ll p = 1000000007;

void solve() {
  ll dp[MAX + 1][M];
  int base = 1;
  int n = strlen(S);
  int c;

  // initialize
  for (int i = 1; i < M; i++)
    dp[0][i] = 0;
  dp[0][0] = 1;

  // dp
  for (int i = 1; i <= n; i++) {
    if (S[n - i] == '?')
      c = -1;
    else
      c = S[n - i] - '0';

    for (int j = 0; j < M; j++)
      dp[i][j] = 0;

    for (int j = 0; j < 10; j++) {
      if (c == -1 || c == j) {
        for (int k = 0; k < M; k++)
          dp[i][(k + j * base) % M] += dp[i - 1][k];
      }
    }

    for (int j = 0; j < M; j++)
      dp[i][j] %= p;
    base *= 10;
    base %= M;
  }

  // result
  printf("%lld\n", dp[n][5]);
}

int main() {
  scanf("%s", S);

  solve();

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAX (int)1e+5
#define M 13
typedef long long ll;

char S[MAX];
static const ll p = 1000000007;

void solve() {
  ll dp[MAX + 1][M];
  int base = 1;
  int n = strlen(S);
  int c;

  // initialize
  for (int i = 1; i < M; i++)
    dp[0][i] = 0;
  dp[0][0] = 1;

  // dp
  for (int i = 1; i <= n; i++) {
    if (S[n - i] == '?')
      c = -1;
    else
      c = S[n - i] - '0';

    for (int j = 0; j < M; j++)
      dp[i][j] = 0;

    for (int j = 0; j < 10; j++) {
      if (c == -1 || c == j) {
        for (int k = 0; k < M; k++)
          dp[i][(k + j * base) % M] += dp[i - 1][k];
      }
    }

    for (int j = 0; j < M; j++)
      dp[i][j] %= p;
    base *= 10;
    base %= M;
  }

  // result
  printf("%lld\n", dp[n][5]);
}

int main() {
  scanf("%s", S);

  solve();

  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

#include <stdio.h>
#include <string>
#include <vector>

#include <cassert>

#include <algorithm>

#include <functional>

#include <cmath>

#include <iomanip>

#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<long long>> dp(1e5, vector<long long>(13));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    int c;
    if (s[i] == '?') {
      c = -1;
    } else {
      c = s[i] - '0';
    }
    for (int j = 0; j < 10; j++) {
      if (c != -1 && c != j) {
        continue;
      } else {
        for (int k = 0; k < 13; k++) {
          dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
        }
      }
    }
    for (int j = 0; j < 13; j++) {
      dp[i + 1][j] %= MOD;
    }
  }
  cout << dp[n][5] << endl;
}


Fixed submission:
#include <iostream>

#include <stdio.h>
#include <string>
#include <vector>

#include <cassert>

#include <algorithm>

#include <functional>

#include <cmath>

#include <iomanip>

#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<long long>> dp(1e5 + 5, vector<long long>(13));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    int c;
    if (s[i] == '?') {
      c = -1;
    } else {
      c = s[i] - '0';
    }
    for (int j = 0; j < 10; j++) {
      if (c != -1 && c != j) {
        continue;
      } else {
        for (int k = 0; k < 13; k++) {
          dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
        }
      }
    }
    for (int j = 0; j < 13; j++) {
      dp[i + 1][j] %= MOD;
    }
  }
  cout << dp[n][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long ll;
ll MOD = 1000000007;
ll dp[10005][13];
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      ll nxt = s[i] - '0';
      if (s[i] == '?') {
        nxt = j;
      }
      for (int k = 0; k < 13; k++) {
        ll rem = (10 * k + nxt) % 13;
        dp[i + 1][rem] += dp[i][k];
        dp[i + 1][rem] %= MOD;
      }
      if (s[i] != '?')
        break;
    }
  }
  cout << dp[n][5] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long ll;
ll MOD = 1000000007;
ll dp[100005][13];
int main() {
  string s;
  cin >> s;
  ll n = s.size();
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      ll nxt = s[i] - '0';
      if (s[i] == '?') {
        nxt = j;
      }
      for (int k = 0; k < 13; k++) {
        ll rem = (10 * k + nxt) % 13;
        dp[i + 1][rem] += dp[i][k];
        dp[i + 1][rem] %= MOD;
      }
      if (s[i] != '?')
        break;
    }
  }
  cout << dp[n][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility> // pair make_pair
#include <vector>

#define m0(x) memset(x, 0, sizeof(x))
#define m1(x) memset(x, 63, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX / 10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int>>;
using WeightGraph = vector<vector<Pi>>;

int dp[10000][20];

signed main() {
  string N;
  cin >> N;
  int l = N.size();
  vector<int> n;
  for (auto a : N) {
    if (a == '?') {
      n.push_back(-1);
    } else {
      n.push_back(a - '0');
    }
  }

  // for (auto b : n) {
  //   cout << b << endl;
  // }

  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 0; i < l; i++) {
    for (int j = 0; j < 13; j++) {
      if (n[i] != -1) {
        dp[i + 1][(j * 10 + n[i]) % 13] += (dp[i][j] % 1000000007);
        dp[i + 1][(j * 10 + n[i]) % 13] %= 1000000007;
      } else {
        for (int x = 0; x <= 9; x++) {
          dp[i + 1][(j * 10 + x) % 13] += (dp[i][j] % 1000000007);
          dp[i + 1][(j * 10 + x) % 13] %= 1000000007;
        }
      }
    }
  }
  cout << dp[l][5] << endl;
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility> // pair make_pair
#include <vector>

#define m0(x) memset(x, 0, sizeof(x))
#define m1(x) memset(x, 63, sizeof(x))
#define fill(x, y) memset(x, y, sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX / 10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int>>;
using WeightGraph = vector<vector<Pi>>;

int dp[100100][20];

signed main() {
  string N;
  cin >> N;
  int l = N.size();
  vector<int> n;
  for (auto a : N) {
    if (a == '?') {
      n.push_back(-1);
    } else {
      n.push_back(a - '0');
    }
  }

  // for (auto b : n) {
  //   cout << b << endl;
  // }

  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 0; i < l; i++) {
    for (int j = 0; j < 13; j++) {
      if (n[i] != -1) {
        dp[i + 1][(j * 10 + n[i]) % 13] += (dp[i][j] % 1000000007);
        dp[i + 1][(j * 10 + n[i]) % 13] %= 1000000007;
      } else {
        for (int x = 0; x <= 9; x++) {
          dp[i + 1][(j * 10 + x) % 13] += (dp[i][j] % 1000000007);
          dp[i + 1][(j * 10 + x) % 13] %= 1000000007;
        }
      }
    }
  }
  cout << dp[l][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const int maxn = 1e3 + 10, mod = 1e9 + 7;
ll dp[maxn][14];
map<int, int> m;

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < 13; i++)
    for (int j = 0; j < 13; j++)
      if ((j * 10) % 13 == i)
        m[i] = j;

  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < 13; j++)
      if (!i) {
        if (s[i] == '?')
          dp[i][j] = (j < 10);
        else
          dp[i][j] = (j == (s[i] - '0'));
      } else if (s[i] == '?')
        for (int t = 0; t < 10; t++)
          dp[i][j] = (dp[i][j] + dp[i - 1][m[(j - t + 13) % 13] % 13]) % mod;
      else
        dp[i][j] = (dp[i - 1][m[(j - (s[i] - '0') + 13) % 13] % 13]);

  cout << dp[s.size() - 1][5];

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const int maxn = 1e5 + 10, mod = 1e9 + 7;
ll dp[maxn][14];
map<int, int> m;

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < 13; i++)
    for (int j = 0; j < 13; j++)
      if ((j * 10) % 13 == i)
        m[i] = j;

  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < 13; j++)
      if (!i) {
        if (s[i] == '?')
          dp[i][j] = (j < 10);
        else
          dp[i][j] = (j == (s[i] - '0'));
      } else if (s[i] == '?')
        for (int t = 0; t < 10; t++)
          dp[i][j] = (dp[i][j] + dp[i - 1][m[(j - t + 13) % 13] % 13]) % mod;
      else
        dp[i][j] = (dp[i - 1][m[(j - (s[i] - '0') + 13) % 13] % 13]);

  cout << dp[s.size() - 1][5];

  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vi vector<int>

#define MOD 1000000007

int main() {

  string S;
  cin >> S;

  vector<vll> dp(10005, vll(13, 0));
  dp[0][0] = 1;

  int c;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '?')
      c = -1;
    else
      c = S[i] - '0';
    for (int j = 0; j < 10; j++) {
      if (c != -1 && c != j)
        continue;
      for (int k = 0; k < 13; k++) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    for (int k = 0; k < 13; k++) {
      dp[i + 1][k] %= MOD;
    }
  }

  cout << dp[S.length()][5] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vi vector<int>

#define MOD 1000000007

int main() {

  string S;
  cin >> S;

  vector<vll> dp(100005, vll(13, 0));
  dp[0][0] = 1;

  int c;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '?')
      c = -1;
    else
      c = S[i] - '0';
    for (int j = 0; j < 10; j++) {
      if (c != -1 && c != j)
        continue;
      for (int k = 0; k < 13; k++) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    for (int k = 0; k < 13; k++) {
      dp[i + 1][k] %= MOD;
    }
  }

  cout << dp[S.length()][5] << endl;

  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
int main() {
  string s;
  cin >> s;
  long long dp[10010][14] = {};
  dp[0][0] = 1;
  int buf = 0;
  long long n;
  n = (int)(s.length());
  for (int i = 1; i <= n; i++) {
    buf = s[i - 1] - '0';
    if (s[i - 1] == '?')
      buf = -1;
    int sum = 0;
    if (buf != -1) {
      for (int j = 0; j < 13; j++) {
        dp[i][(j * 10 + buf) % 13] = dp[i - 1][j];
        dp[i][(j * 10 + buf) % 13] %= mod;
      }
    } else {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k < 10; k++) {
          dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
          dp[i][(j * 10 + k) % 13] %= mod;
        }
      }
    }
  }
  cout << dp[n][5] << endl;
  //  cout<<n<<endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1000000007;
int main() {
  string s;
  cin >> s;
  long long dp[100010][14] = {};
  dp[0][0] = 1;
  int buf = 0;
  long long n;
  n = (int)(s.length());
  for (int i = 1; i <= n; i++) {
    buf = s[i - 1] - '0';
    if (s[i - 1] == '?')
      buf = -1;
    int sum = 0;
    if (buf != -1) {
      for (int j = 0; j < 13; j++) {
        dp[i][(j * 10 + buf) % 13] = dp[i - 1][j];
        dp[i][(j * 10 + buf) % 13] %= mod;
      }
    } else {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k < 10; k++) {
          dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
          dp[i][(j * 10 + k) % 13] %= mod;
        }
      }
    }
  }
  cout << dp[n][5] << endl;
  //  cout<<n<<endl;
  return 0;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

const long long MOD = 1000000007;

int main() {
  string S;
  cin >> S;

  int n = S.size(), D = 13;

  long long dp[10001][13] = {}, num, m = 1, rest;

  dp[0][0] = 1;

  for (int k = 0; k < n; ++k) {
    for (int d = 0; d < D; ++d) {
      if (S[n - 1 - k] == '?') {
        for (num = 0; num < 10; ++num) {
          rest = (d + num * m) % D;
          dp[k + 1][rest] += dp[k][d];
          dp[k + 1][rest] %= MOD;
        }
      } else {
        num = S[n - 1 - k] - '0';
        rest = (d + num * m) % D;
        dp[k + 1][rest] += dp[k][d];
        dp[k + 1][rest] %= MOD;
      }
    }
    m *= 10;
    m %= D;
  }

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


Fixed submission:
#include <iostream>
#include <string>
using namespace std;

const long long MOD = 1000000007;

int main() {
  string S;
  cin >> S;

  int n = S.size(), D = 13;

  long long dp[100001][13] = {}, num, m = 1, rest;

  dp[0][0] = 1;

  for (int k = 0; k < n; ++k) {
    for (int d = 0; d < D; ++d) {
      if (S[n - 1 - k] == '?') {
        for (num = 0; num < 10; ++num) {
          rest = (d + num * m) % D;
          dp[k + 1][rest] += dp[k][d];
          dp[k + 1][rest] %= MOD;
        }
      } else {
        num = S[n - 1 - k] - '0';
        rest = (d + num * m) % D;
        dp[k + 1][rest] += dp[k][d];
        dp[k + 1][rest] %= MOD;
      }
    }
    m *= 10;
    m %= D;
  }

  cout << dp[n][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
int n, m, x, y, q, d;
ll z, w = 0, sum = 0;
int ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
  int dp[10010][13];
  string s;
  int d;
  cin >> s;
  Fill(dp, 0);
  dp[0][0] = 1;
  rep(i, s.size()) {
    if (isdigit(s[i])) {
      int Si = s[i] - '0';
      rep(j, 13) {
        dp[i + 1][(j * 10 + Si) % 13] += dp[i][j];
        dp[i + 1][(j * 10 + Si) % 13] %= MOD;
      }
    } else {
      rep(j, 13) {
        rep(k, 10) {
          dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
          dp[i + 1][(j * 10 + k) % 13] %= MOD;
        }
      }
    }
  }
  cout << dp[s.size()][5] << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
int n, m, x, y, q, d;
ll z, w = 0, sum = 0;
int ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
  int dp[100100][13];
  string s;
  int d;
  cin >> s;
  Fill(dp, 0);
  dp[0][0] = 1;
  rep(i, s.size()) {
    if (isdigit(s[i])) {
      int Si = s[i] - '0';
      rep(j, 13) {
        dp[i + 1][(j * 10 + Si) % 13] += dp[i][j];
        dp[i + 1][(j * 10 + Si) % 13] %= MOD;
      }
    } else {
      rep(j, 13) {
        rep(k, 10) {
          dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
          dp[i + 1][(j * 10 + k) % 13] %= MOD;
        }
      }
    }
  }
  cout << dp[s.size()][5] << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
#define ll long long
const ll md = 1e9 + 7;
ll dp[N][15];
string s;
int n;
ll solve(int idx, int val) {
  ll &ret = dp[idx][val];
  if (ret >= 0)
    return ret;
  ret = 0;
  if (idx == n) {
    ret = (val == 5);
  }
  if (s[idx] == '?') {
    int tmp;
    for (int i = 0; i < 10; i++) {
      tmp = (val * 10 + i) % 13;
      ret += (solve(idx + 1, tmp));
      ret %= md;
    }
  } else {
    int v = s[idx] - '0';
    val = (val * 10 + v) % 13;
    ret += solve(idx + 1, val);
    ret %= md;
  }
  return ret %= md;
}

int main() {
  cin >> s;
  n = s.size();
  memset(dp, -1ll, sizeof(dp));

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
#define ll long long
const ll md = 1e9 + 7;
ll dp[N][15];
string s;
int n;
ll solve(int idx, int val) {
  ll &ret = dp[idx][val];
  if (ret >= 0)
    return ret;
  ret = 0;
  if (idx == n) {
    ret = (val == 5);
    return ret;
  }
  if (s[idx] == '?') {
    int tmp;
    for (int i = 0; i < 10; i++) {
      tmp = (val * 10 + i) % 13;
      ret += (solve(idx + 1, tmp));
      ret %= md;
    }
  } else {
    int v = s[idx] - '0';
    val = (val * 10 + v) % 13;
    ret += solve(idx + 1, val);
    ret %= md;
  }
  return ret %= md;
}

int main() {
  cin >> s;
  n = s.size();
  memset(dp, -1ll, sizeof(dp));

  cout << solve(0, 0) << endl;
}
Problem p02960 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  ll dp[15][11000] = {};

  dp[0][0] = 1;
  rep(i, s.size()) {
    if (s[i] == '?') {
      rep(j, 13) {
        rep(num, 10) {
          dp[(j * 10 + num) % 13][i + 1] += dp[j][i];
          dp[(j * 10 + num) % 13][i + 1] %= MOD;
        }
      }
    } else {
      int num = s[i] - '0';
      rep(j, 13) {
        dp[(j * 10 + num) % 13][i + 1] += dp[j][i];
        dp[(j * 10 + num) % 13][i + 1] %= MOD;
      }
    }
  }
  cout << dp[5][s.size()] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  ll dp[15][110000] = {};

  dp[0][0] = 1;
  rep(i, s.size()) {
    if (s[i] == '?') {
      rep(j, 13) {
        rep(num, 10) {
          dp[(j * 10 + num) % 13][i + 1] += dp[j][i];
          dp[(j * 10 + num) % 13][i + 1] %= MOD;
        }
      }
    } else {
      int num = s[i] - '0';
      rep(j, 13) {
        dp[(j * 10 + num) % 13][i + 1] += dp[j][i];
        dp[(j * 10 + num) % 13][i + 1] %= MOD;
      }
    }
  }
  cout << dp[5][s.size()] << endl;
  return 0;
}
Problem p02962 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
char laz[maxn];
int pi[8 * maxn], dp[8 * maxn];
int prefix_function(const string &s, const string &t) {
  /// search t on s
  int m = (int)t.length();
  int n = t.length() + s.length() + 1;
  auto ss = [&](int idx) {
    if (idx == m)
      return '#';
    if (idx < m)
      return t[idx];
    return s[idx - m - 1];
  };
  pi[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && ss(i) != ss(j))
      j = pi[j - 1];
    if (ss(i) == ss(j))
      j++;
    pi[i] = j;
  }
  int ma = -1;
  for (int i = n - 1; i > m; i--) {
    dp[i] = 0;
    if (pi[i] == m) {
      dp[i] = 1;
    }
    if (i + m < n && dp[i] == 1) {
      dp[i] += dp[i + m];
    }
    ma = max(ma, dp[i]);
  }
  return ma;
}
string s, t, a, ss, tt;
/**
There exists a non-negative integer j
such that the concatenation of i copies of t
is a substring of the concatenation of j copies of s.
*/

int main() {
  scanf("%s", laz);
  ss = string(laz);
  scanf("%s", laz);
  t = string(laz);
  s = ss;
  while ((int)s.length() <= (int)t.length() + (int)ss.length()) {
    s += ss;
  }
  s += ss;
  int c = prefix_function(s, t);
  if (c == -1) {
    return !printf("0");
  }
  s += s;
  int cc = prefix_function(s, t);
  if (cc == c) {
    return !printf("%d\n", cc);
  } else {
    return !printf("-1");
  }
}
/*
    Good Luck
        -Lci70121
*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
char laz[maxn];
int pi[12 * maxn], dp[12 * maxn];
int prefix_function(const string &s, const string &t) {
  /// search t on s
  int m = (int)t.length();
  int n = t.length() + s.length() + 1;
  auto ss = [&](int idx) {
    if (idx == m)
      return '#';
    if (idx < m)
      return t[idx];
    return s[idx - m - 1];
  };
  pi[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && ss(i) != ss(j))
      j = pi[j - 1];
    if (ss(i) == ss(j))
      j++;
    pi[i] = j;
  }
  int ma = -1;
  for (int i = n - 1; i > m; i--) {
    dp[i] = 0;
    if (pi[i] == m) {
      dp[i] = 1;
    }
    if (i + m < n && dp[i] == 1) {
      dp[i] += dp[i + m];
    }
    ma = max(ma, dp[i]);
  }
  return ma;
}
string s, t, a, ss, tt;
/**
There exists a non-negative integer j
such that the concatenation of i copies of t
is a substring of the concatenation of j copies of s.
*/

int main() {
  scanf("%s", laz);
  ss = string(laz);
  scanf("%s", laz);
  t = string(laz);
  s = ss;
  while ((int)s.length() <= (int)t.length() + (int)ss.length()) {
    s += ss;
  }
  s += ss;
  int c = prefix_function(s, t);
  if (c == -1) {
    return !printf("0");
  }
  s += s;
  int cc = prefix_function(s, t);
  if (cc == c) {
    return !printf("%d\n", cc);
  } else {
    return !printf("-1");
  }
}
/*
    Good Luck
        -Lci70121
*/
Problem p02962 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;

const int maxn = 1e5 + 10;
int f[maxn], deg[maxn], dist[maxn];
vector<int> adj[maxn];

void getfail(string p) {
  int n = p.size();
  for (int i = 1; i < n; ++i) {
    int j = f[i];
    while (j && p[j] != p[i])
      j = f[j];
    if (p[j] == p[i])
      f[i + 1] = j + 1;
  }
}

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  ios::sync_with_stdio(false);
  string s, t, s1;
  cin >> s >> t;
  getfail(t);
  s1 = s;
  int m = t.size(), n = s.size();
  while (s.size() < s1.size() + t.size())
    s += s1;

  int j = 0;
  for (int i = 0; i < n + m; ++i) {
    while (j && t[j] != s[i])
      j = f[j];
    if (t[j] == s[i])
      ++j;
    if (j == m)
      adj[(i - m + 1) % n].push_back((i + 1) % n), ++deg[(i + 1) % n];
  }

  queue<int> q;
  int ans = 0;
  for (int i = 0; i < n; ++i)
    if (deg[i] == 0)
      q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : adj[u])
      if (--deg[v] == 0)
        q.push(v), dist[v] = max(dist[v], dist[u] + 1), ans = max(ans, dist[v]);
    ;
  }

  int ok = 1;
  for (int i = 0; i < n; ++i)
    if (deg[i]) {
      ok = 0;
      break;
    }

  if (!ok)
    cout << -1;
  else
    cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;

const int maxn = 1e6 + 10;
int f[maxn], deg[maxn], dist[maxn];
vector<int> adj[maxn];

void getfail(string p) {
  int n = p.size();
  for (int i = 1; i < n; ++i) {
    int j = f[i];
    while (j && p[j] != p[i])
      j = f[j];
    if (p[j] == p[i])
      f[i + 1] = j + 1;
  }
}

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  ios::sync_with_stdio(false);
  string s, t, s1;
  cin >> s >> t;
  getfail(t);
  s1 = s;
  int m = t.size(), n = s.size();
  while (s.size() < s1.size() + t.size())
    s += s1;

  int j = 0;
  for (int i = 0; i < n + m; ++i) {
    while (j && t[j] != s[i])
      j = f[j];
    if (t[j] == s[i])
      ++j;
    if (j == m)
      adj[(i - m + 1) % n].push_back((i + 1) % n), ++deg[(i + 1) % n];
  }

  queue<int> q;
  int ans = 0;
  for (int i = 0; i < n; ++i)
    if (deg[i] == 0)
      q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : adj[u])
      if (--deg[v] == 0)
        q.push(v), dist[v] = max(dist[v], dist[u] + 1), ans = max(ans, dist[v]);
    ;
  }

  int ok = 1;
  for (int i = 0; i < n; ++i)
    if (deg[i]) {
      ok = 0;
      break;
    }

  if (!ok)
    cout << -1;
  else
    cout << ans;
  return 0;
}