Problem p03088 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test()                                                                 \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define prsp(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], sp;                                       \
  nl;
#define prpsp(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, sp;                    \
  nl;
#define prnl(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], nl;                                       \
  nl;
#define prpnl(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, nl;                    \
  nl;
#define MOD 1000000007
#define mod(n) (((n % MOD) + MOD) % MOD)
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
int dp[105][5][5][5];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio();

  int n;
  cin >> n;
  dp[0][0][0][0] = 1;
  loop(i, 0, n) loop(j, 0, 5) loop(k, 0, 5) loop(l, 0, 5) {
    loop(m, 0, 4) {
      if (k == 1 && l == 2 && m == 3)
        continue;
      if (k == 1 && l == 3 && m == 2)
        continue;
      if (k == 3 && l == 1 && m == 2)
        continue;
      if (j == 1 && l == 3 && m == 2)
        continue;
      if (j == 1 && k == 3 && m == 2)
        continue;

      dp[i + 1][k][l][m] += dp[i][j][k][l];
      dp[i + 1][k][l][m] = mod(dp[i + 1][k][l][m]);
    }
  }

  ll ans = 0;
  loop(j, 0, 5) loop(k, 0, 5) loop(l, 0, 5) {
    ans += dp[n][j][k][l];
    ans = mod(ans);
  }
  cout << ans, nl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define test()                                                                 \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define pb push_back
#define mkp make_pair
#define nl cout << "\n"
#define sp cout << " "
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define prsp(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], sp;                                       \
  nl;
#define prpsp(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, sp;                    \
  nl;
#define prnl(v)                                                                \
  loop(i, 0, v.size()) cout << v[i], nl;                                       \
  nl;
#define prpnl(v)                                                               \
  loop(i, 0, v.size()) cout << v[i].F << " " << v[i].S, nl;                    \
  nl;
#define MOD 1000000007
#define mod(n) (((n % MOD) + MOD) % MOD)
#define all(x) x.begin(), x.end()

const int N = 1e5 + 5;
int dp[105][5][5][5];

int main() {
  fastio();

  int n;
  cin >> n;
  dp[0][0][0][0] = 1;
  loop(i, 0, n) loop(j, 0, 5) loop(k, 0, 5) loop(l, 0, 5) {
    loop(m, 0, 4) {
      if (k == 1 && l == 2 && m == 3)
        continue;
      if (k == 1 && l == 3 && m == 2)
        continue;
      if (k == 3 && l == 1 && m == 2)
        continue;
      if (j == 1 && l == 3 && m == 2)
        continue;
      if (j == 1 && k == 3 && m == 2)
        continue;

      dp[i + 1][k][l][m] += dp[i][j][k][l];
      dp[i + 1][k][l][m] = mod(dp[i + 1][k][l][m]);
    }
  }

  ll ans = 0;
  loop(j, 0, 5) loop(k, 0, 5) loop(l, 0, 5) {
    ans += dp[n][j][k][l];
    ans = mod(ans);
  }
  cout << ans, nl;

  return 0;
}