Problem p02960 (C++)

Buggy submission (status: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

using namespace std;

class DDigitsParade {
public:
  ll T[13][100000];
  string S;

  void solve(std::istream &in, std::ostream &out) {
    REP(i, 13) REP(j, 100000) T[i][j] = 0;
    in >> S;

    if (S[0] == '?')
      FOR(i, 0, 10) T[i][0]++;
    else
      T[S[0] - '0'][0]++;

    FOR(i, 1, S.length()) {
      if (S[i] == '?') {
        FOR(num, 0, 10) FOR(res, 0, 13) {
          T[(res * 10 + num) % 13][i] += T[res][i - 1];
          T[(res * 10 + num) % 13][i] %= MOD;
        }
      } else {
        int num = S[i] - '0';
        FOR(res, 0, 13) {
          T[(res * 10 + num) % 13][i] += T[res][i - 1];
          T[(res * 10 + num) % 13][i] %= MOD;
        }
      }
    }

    COUT(T[S.length() - 1][5]);
  }
};

int main() {
  DDigitsParade solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

using namespace std;

class DDigitsParade {
public:
  ll T[13][100000];
  string S;

  void solve(std::istream &in, std::ostream &out) {
    REP(i, 13) REP(j, 100000) T[i][j] = 0;
    in >> S;

    if (S[0] == '?')
      FOR(i, 0, 10) T[i][0]++;
    else
      T[S[0] - '0'][0]++;

    FOR(i, 1, S.length()) {
      if (S[i] == '?') {
        FOR(num, 0, 10) FOR(res, 0, 13) {
          T[(res * 10 + num) % 13][i] += T[res][i - 1];
          T[(res * 10 + num) % 13][i] %= MOD;
        }
      } else {
        int num = S[i] - '0';
        FOR(res, 0, 13) {
          T[(res * 10 + num) % 13][i] += T[res][i - 1];
          T[(res * 10 + num) % 13][i] %= MOD;
        }
      }
    }

    COUT(T[5][S.length() - 1]);
  }
};

int main() {
  DDigitsParade solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}