Problem p02555 (C++) — buggy submission, verdict: Runtime Error

/**
 * @File   : atcoder.cpp
 * @Author : pasnger
 * @Date   : 13/9/2020, 5:10:33 pm
 */

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

#define INF 2e18
#define int long long
#define f(i, a, b) for (int i = (a); i < (b); (i)++)
#define fe(i, a, b) for (int i = (a); i <= (b); (i)++)
#define rf(i, a, b) for (int i = (a); i > (b); (i)--)
#define rfe(i, a, b) for (int i = (a); i >= (b); (i)--)
#define ff(ele, cont) for (auto(ele) : (cont))
#define pb push_back;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef set<int> si;
typedef multiset<int> msi;

const int mxn = 1e6 + 4;
const int mod = 1e9 + 7;
const double pi = acos(-1);

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\\n"; }
template <typename T, typename... Args> void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args))
    cerr << ", ";
  DBG(args...);
}
int mul(int x, int y) {
  int res = x * y;
  if (res >= mod)
    res %= mod;
  return res;
}

int power(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    y = y >> 1;
    x = mul(x, x);
  }
  return res;
}
int add(int x, int y) {
  int res = x + y;
  if (res >= mod)
    res -= mod;
  return res;
}

/////////////////////////// GLOBAL ///////////////////////////
int dp[20004];
/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  int n;
  cin >> n;

  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  fe(i, 6, n) {
    fe(j, 3, n) {
      if (i - j >= 3)
        dp[i] = add(dp[i - j], dp[i]);
    }
    dp[i]++;
  }
  cout << dp[n] << "\\n";
}

int32_t main() {
#ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
#ifndef ONLINE_JUDGE
  cerr << "\\nRun Time -> " << (double)(clock() - tStart) / CLOCKS_PER_SEC
       << " sec\\n";
#endif
}


Error: WA

Fixed submission:

/**
 * @File   : atcoder.cpp
 * @Author : pasnger
 * @Date   : 13/9/2020, 5:10:33 pm
 */

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

#define INF 2e18
#define int long long
#define f(i, a, b) for (int i = (a); i < (b); (i)++)
#define fe(i, a, b) for (int i = (a); i <= (b); (i)++)
#define rf(i, a, b) for (int i = (a); i > (b); (i)--)
#define rfe(i, a, b) for (int i = (a); i >= (b); (i)--)
#define ff(ele, cont) for (auto(ele) : (cont))
#define pb push_back;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef set<int> si;
typedef multiset<int> msi;

const int mxn = 1e6 + 4;
const int mod = 1e9 + 7;
const double pi = acos(-1);

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\\n"; }
template <typename T, typename... Args> void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args))
    cerr << ", ";
  DBG(args...);
}
int mul(int x, int y) {
  int res = x * y;
  if (res >= mod)
    res %= mod;
  return res;
}

int power(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = mul(res, x);
    y = y >> 1;
    x = mul(x, x);
  }
  return res;
}
int add(int x, int y) {
  int res = x + y;
  if (res >= mod)
    res -= mod;
  return res;
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  int n;
  cin >> n;
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  fe(i, 6, n) {
    fe(j, 3, n) {
      if (i - j >= 3)
        dp[i] = add(dp[i - j], dp[i]);
    }
    dp[i]++;
  }
  cout << dp[n] << "\\n";
}

int32_t main() {
#ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    // cout << "Case #"<<tt<<": ";
    solve();
  }
#ifndef ONLINE_JUDGE
  cerr << "\\nRun Time -> " << (double)(clock() - tStart) / CLOCKS_PER_SEC
       << " sec\\n";
#endif
}