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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<long long int> v1;
  vector<long long int> v2;
  for (int i = a; i <= b; i++) {
    v1.push_back(i);
  }
  for (int i = c; i <= d; i++) {
    v2.push_back(i);
  }
  long long int res = v1[0] * v2[0];
  for (int i = 0; i < v1.size(); i++) {
    for (int j = 0; j < v2.size(); j++) {
      if (v1[i] * v2[j] >= res) {
        res = v1[i] * v2[j];
      }
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  long long int a1 = a * c;
  long long int a2 = a * d;
  long long int a3 = b * c;
  long long int a4 = b * d;
  long long int x = max(a1, a2);
  long long int y = max(a3, a4);
  long long int z = max(x, y);
  cout << z << endl;
}
Problem p02553 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll a[4];
  while (1) {
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    vector<ll> b;
    b.push_back(a[0] * a[2]);
    b.push_back(a[0] * a[3]);
    b.push_back(a[1] * a[2]);
    b.push_back(a[1] * a[3]);
    sort(b.begin(), b.end());
    cout << b[3] << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  vector<ll> b;
  b.push_back(a[0] * a[2]);
  b.push_back(a[0] * a[3]);
  b.push_back(a[1] * a[2]);
  b.push_back(a[1] * a[3]);
  sort(b.begin(), b.end());
  cout << b[3] << endl;
  return 0;
}
Problem p02553 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;

int main() {
  long a, b, c, d;
  long max = LONG_MIN;
  cin >> a >> b >> c >> d;
  for (int i = a; i <= b; i++) {
    for (int j = c; j <= d; j++) {
      if (i * j > max)
        max = i * j;
    }
  }
  cout << max << 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 rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int, int>;
using pq = priority_queue<int>;
typedef long long ll;

int main() {
  long a, b, c, d;
  long max = LONG_MIN;
  cin >> a >> b >> c >> d;
  long A, B, C, D;
  A = a * c;
  B = a * d;
  C = b * c;
  D = b * d;
  priority_queue<long> pq;
  pq.push(A);
  pq.push(B);
  pq.push(C);
  pq.push(D);
  cout << pq.top() << endl;
  return (0);
}
Problem p02553 (C++)

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

using namespace std;

long int a, b, c, d;

int solve() {
  long int ans = a * c;
  if (a * d > ans) {
    ans = a * d;
  }

  if (b * c > ans) {
    ans = b * c;
  }

  if (b * d > ans) {
    ans = b * d;
  }

  cout << ans;
}

int main() {
  cin >> a >> b >> c >> d;
  solve();
}

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

using namespace std;

long int a, b, c, d;

void solve() {
  long int ans = a * c;
  if (a * d > ans) {
    ans = a * d;
  }

  if (b * c > ans) {
    ans = b * c;
  }

  if (b * d > ans) {
    ans = b * d;
  }

  cout << ans;
}

int main() {
  cin >> a >> b >> c >> d;
  solve();
}
Problem p02553 (C++)

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

using namespace std;

int main() {
  long a, b, c, d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  return b * d;
}

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

using namespace std;

int main() {
  long a, b, c, d;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cout << max({a * c, b * d, a * d, b * c}) << endl;
  return 0;
}
Problem p02553 (C++)

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

int main() {
  long long a, b, c, d;

  cin >> a >> b >> c >> d;

  long long ans = -1000000000000000000;

  for (long long i = a; i <= b; i++) {
    for (long long j = c; j <= d; j++) {
      long long cnt = i * j;
      ans = max(cnt, ans);
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  long long a, b, c, d;

  cin >> a >> b >> c >> d;

  long long ans = -1000000000000000000;

  long long cnt[4] = {a * c, a * d, b * c, b * d};

  for (long long i = 0; i < 4; i++)
    ans = max(ans, cnt[i]);

  cout << ans << endl;

  return 0;
}
Problem p02553 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc178/tasks/abc178_b
#include <iostream>
#include <vector>
using namespace std;
#define ll long long int
int main() {
  ll a[5], b[5], ans;
  cin >> a[0] >> a[1] >> b[0] >> b[1];
  ll mx = (ll)(-1e10);
  for (ll i = a[0]; i <= a[1]; i++) {
    for (ll j = b[0]; j <= b[1]; j++) {
      ans = i * j;
      mx = max(ans, mx);
    }
  }

  cout << mx << "\n";
}


Fixed submission:
// https://atcoder.jp/contests/abc178/tasks/abc178_b
#include <iostream>
#include <vector>
using namespace std;
#define ll long long int
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll mx = a * c;
  if (a <= 0 && c <= 0)
    mx = max(mx, a * c);
  if (b >= 0 && d >= 0)
    mx = max(mx, b * d);
  mx = max(mx, a * d);
  mx = max(mx, b * c);

  cout << mx << "\n";
}
Problem p02553 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans1 = b * d;
  ll ans2 = b * d;
  ll x = b;
  ll y = d;
  ll ans3 = a * c;
  while (x > a) {
    x--;
    ans1 = max(ans1, x * d); // a<x<b; c<y<d
  }
  ans1 = max(ans1, ans3);
  while (y > c) {
    y--;
    ans2 = max(ans2, y * b);
  }
  ans2 = max(ans2, ans3);
  cout << max(ans1, ans2);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x, y;
  ll maxi = -1e18;
  maxi = max({maxi, a * c, b * d, a * d, b * c});
  cout << maxi;
}
Problem p02553 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
int main() {
  IOS;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll res = -0x3f3f3f3f3f3f3f3f;
  rep(i, a, b) {
    rep(j, c, d) { res = max(res, 1LL * i * j); }
  }
  cout << res;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
int main() {
  IOS;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll res1, res2, res3, res4;
  res1 = a * c;
  res2 = a * d;
  res3 = b * c;
  res4 = b * d;
  ll ans = -0x3f3f3f3f3f3f3f3f;
  ans = max(ans, res1);
  ans = max(ans, res2);
  ans = max(ans, res3);
  ans = max(ans, res4);
  if ((a <= 0 && b >= 0) || (c <= 0 && d >= 0))
    ans = max(ans, 1LL * 0);
  cout << ans;
}
Problem p02554 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0), eps = 1e-8;
const ll mod = 1e9 + 7;
const int inf = 1e18;
const int maxn = 5e5 + 5;
ll POW(ll a, ll b) {
  ll ans = 1;
  b %= (mod - 1);
  while (b) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
ll inv(ll a) { return POW(a, mod - 2); }
ll fac[maxn], ifac[maxn];
void init() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < maxn; i++)
    fac[i] = fac[i - 1] * i % mod;
  ifac[maxn - 1] = inv(fac[maxn - 1]);
  for (int i = maxn - 2; i >= 0; i--)
    ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
ll getc(int n, int m) {
  if (n < m || m < 0)
    return 0;
  return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main() {
  int n;
  cin >> n;
  init();
  if (n == 1)
    cout << 0 << endl;
  else if (n == 2)
    cout << 2 << endl;
  else {
    ll ans = POW(10, n);
    ans = (ans + mod - POW(8, n)) % mod;
    ll res = 1;
    for (int i = 1; i <= n; i++) {
      res = (res + getc(n, i) % mod * POW(8, n - i) % mod) % mod;
    }
    ans = (ans + mod - res * 2 % mod) % mod;
    cout << (ans + 2) % mod << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0), eps = 1e-8;
const ll mod = 1e9 + 7;
const int inf = 1e18;
const int maxn = 1e6 + 5;
ll POW(ll a, ll b) {
  ll ans = 1;
  b %= (mod - 1);
  while (b) {
    if (b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
ll inv(ll a) { return POW(a, mod - 2); }
ll fac[maxn], ifac[maxn];
void init() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i < maxn; i++)
    fac[i] = fac[i - 1] * i % mod;
  ifac[maxn - 1] = inv(fac[maxn - 1]);
  for (int i = maxn - 2; i >= 0; i--)
    ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
ll getc(int n, int m) {
  if (n < m || m < 0)
    return 0;
  return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main() {
  int n;
  cin >> n;
  init();
  if (n == 1)
    cout << 0 << endl;
  else if (n == 2)
    cout << 2 << endl;
  else {
    ll ans = POW(10, n);
    ans = (ans + mod - POW(8, n)) % mod;
    ll res = 1;
    for (int i = 1; i <= n; i++) {
      res = (res + getc(n, i) % mod * POW(8, n - i) % mod) % mod;
    }
    ans = (ans + mod - res * 2 % mod) % mod;
    cout << (ans + 2) % mod << endl;
  }
  return 0;
}
Problem p02554 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
ll int n, k;
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  ll int mod = 1e9 + 7;
  ll int ans1 = 1, ans2 = 1, ans3 = 1;
  for (int i = 0; i < n; i++) {
    ans1 = ans1 * 10;
    ans1 %= mod;
    ans2 = ans2 * 9;
    ans2 %= mod;
    ans3 = ans3 * 8;
    ans3 %= mod;
  }
  ll int ans_final = (ans1 - 2 * ans2 + ans3 + mod) % mod;
  while (ans_final < 0)
    ans_final %= mod;
  cout << ans_final;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define w(x)                                                                   \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
ll int n, k;
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  ll int mod = 1e9 + 7;
  ll int ans1 = 1, ans2 = 1, ans3 = 1;
  for (int i = 0; i < n; i++) {
    ans1 = ans1 * 10;
    ans1 %= mod;
    ans2 = ans2 * 9;
    ans2 %= mod;
    ans3 = ans3 * 8;
    ans3 %= mod;
  }
  ll int ans_final = (ans1 - 2 * ans2 + ans3 + mod) % mod;
  while (ans_final < 0)
    ans_final += mod;
  cout << ans_final;
}
Problem p02554 (C++)

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

#define int long long

using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int n, dp[N][2][2];

void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (dp[i][j][k]) {
          for (int nxt = 0; nxt <= 9; nxt++) {
            add(dp[i + 1][j | (nxt == 0)][k | (nxt == 9)], dp[i][j][k]);
          }
        }
      }
    }
  }

  cout << dp[n][1][1];
  return 0;
}


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

#define int long long

using namespace std;

const int N = 1e6 + 5;
const int mod = 1e9 + 7;

int n, dp[N][2][2];

void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (dp[i][j][k]) {
          for (int nxt = 0; nxt <= 9; nxt++) {
            add(dp[i + 1][j | (nxt == 0)][k | (nxt == 9)], dp[i][j][k]);
          }
        }
      }
    }
  }

  cout << dp[n][1][1];
  return 0;
}
Problem p02554 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie();                                                                   \
  cout.tie(0)
#define inf 0x3f3f3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
ll f[N], invs[N];
ll pows(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return ans % mod;
}
ll inv(ll a) // 求逆元
{
  return pows(a, mod - 2);
}
ll C(ll n, ll m) // 组合数公式
{
  return f[m] * inv(f[n]) % mod * inv(f[m - n]) % mod;
  // return f[m]*invs[n]%mod*invs[m-n]%mod;
}
int main() {

  ll n;
  f[0] = 1;
  for (ll i = 1; i < N; i++) {
    f[i] = f[i - 1] * i % mod;
    invs[i] = inv(f[i]) % mod;
  }
  cin >> n;
  if (n < 2) {
    cout << 0 << endl;
  } else {
    ll sum = 0;
    for (ll i = 1; i < n; i++) {
      for (ll j = 1; j <= n - i; j++) {
        sum = (sum +
               C(i, n) % mod * C(j, n - i) % mod * pows(8, n - i - j) % mod) %
              mod;
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
#define IO                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie();                                                                   \
  cout.tie(0)
#define inf 0x3f3f3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
ll f[N], invs[N];
ll pows(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1) {
      ans = ans * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return ans % mod;
}
ll inv(ll a) // 求逆元
{
  return pows(a, mod - 2);
}
ll C(ll n, ll m) // 组合数公式
{
  return f[m] * inv(f[n]) % mod * inv(f[m - n]) % mod;
  // return f[m]*invs[n]%mod*invs[m-n]%mod;
}
int main() {

  ll n;
  f[0] = 1;
  for (ll i = 1; i < N; i++) {
    f[i] = f[i - 1] * i % mod;
    invs[i] = inv(f[i]) % mod;
  }
  cin >> n;
  if (n < 2) {
    cout << 0 << endl;
  } else {
    ll sum = 0;
    for (ll i = 2; i <= n; i++) {
      sum = (sum +
             C(i, n) % mod * (pows(2, i) - 2) % mod * pows(8, n - i) % mod) %
            mod;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02554 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7, N = 1e6 + 10;
ll n, f[N], po[N];
ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
ll c(int n, int m) {
  return po[n] * ksm(po[m], mod - 2) % mod * ksm(po[n - m], mod - 2) % mod;
}
int main() {
  cin >> n;
  ll ans = 0;
  po[0] = 1;
  for (int i = 1; i <= n; i++)
    po[i] = po[i - 1] * i % mod;
  ll x = 4, y = ksm(8, n - 2), p = ksm(8, mod - 2);
  for (int i = 2; i <= n; i++) {
    ans = (ans + c(n, i) * (((x - 2) % mod + mod) % mod) % mod * y % mod) % mod;
    x = x * 2 % mod;
    y = y * p % mod;
  }
  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7, N = 1e6 + 10;
ll n, f[N], po[N];
ll ksm(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
ll c(int n, int m) {
  return po[n] * ksm(po[m], mod - 2) % mod * ksm(po[n - m], mod - 2) % mod;
}
int main() {
  cin >> n;
  if (n == 1) {
    cout << 0;
    return 0;
  }
  ll ans = 0;
  po[0] = 1;
  for (int i = 1; i <= n; i++)
    po[i] = po[i - 1] * i % mod;
  ll x = 4, y = ksm(8, n - 2), p = ksm(8, mod - 2);
  for (int i = 2; i <= n; i++) {
    ans = (ans + c(n, i) * (((x - 2) % mod + mod) % mod) % mod * y % mod) % mod;
    x = x * 2 % mod;
    y = y * p % mod;
  }
  cout << ans;

  return 0;
}
Problem p02554 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**9)

n = int(input())
mod = 10**9 + 7

# 再帰だとなんか通らん
# dp = {}
# def rec(i, zero, nine):
#     if (i, zero, nine) in dp:
#         return dp[(i, zero, nine)]
#     if i == n:
#         return 1 if (zero and nine) else 0
#     ret = 0
#     for j in range(10):
#         if j == 0:
#             ret += rec(i + 1, True, nine)
#         elif j == 9:
#             ret += rec(i + 1, zero, True)
#         else:
#             ret += rec(i + 1, zero, nine)
#         ret %= mod
#     dp[(i, zero, nine)] = ret
#     return ret

# print(rec(0, False, False))

dp = [[[0 for _ in range(2)] for _ in range(2)] for _ in range(10**6)]
dp[0][0][0] = 1  # どういう意味なのかは不明
for i in range(n):
    for j in range(2):
        for k in range(2):
            for m in range(10):
                if m == 0:
                    dp[i + 1][1][k] += dp[i][j][k]
                    dp[i + 1][1][k] %= mod
                elif m == 9:
                    dp[i + 1][j][1] += dp[i][j][k]
                    dp[i + 1][j][1] %= mod
                else:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j][k] %= mod
print(dp[n][1][1])
# 869121

# 2511445


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n = int(input())
mod = 10**9 + 7

# 再帰だとなんか通らん
# dp = {}
# def rec(i, zero, nine):
#     if (i, zero, nine) in dp:
#         return dp[(i, zero, nine)]
#     if i == n:
#         return 1 if (zero and nine) else 0
#     ret = 0
#     for j in range(10):
#         if j == 0:
#             ret += rec(i + 1, True, nine)
#         elif j == 9:
#             ret += rec(i + 1, zero, True)
#         else:
#             ret += rec(i + 1, zero, nine)
#         ret %= mod
#     dp[(i, zero, nine)] = ret
#     return ret

# print(rec(0, False, False))

dp = [[[0 for _ in range(2)] for _ in range(2)] for _ in range(10**6 + 10101)]
dp[0][0][0] = 1  # どういう意味なのかは不明
for i in range(n):
    for j in range(2):
        for k in range(2):
            for m in range(10):
                if m == 0:
                    dp[i + 1][1][k] += dp[i][j][k]
                    dp[i + 1][1][k] %= mod
                elif m == 9:
                    dp[i + 1][j][1] += dp[i][j][k]
                    dp[i + 1][j][1] %= mod
                else:
                    dp[i + 1][j][k] += dp[i][j][k]
                    dp[i + 1][j][k] %= mod
print(dp[n][1][1])
# 869121

# 2511445
Problem p02554 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z) {
  if (y == 0)
    return 1;
  else {
    ll p = power(x, y / 2, z);
    ll w = (p * p) % z;
    if (y % 2 == 0)
      return w;
    else
      return (x * w) % z;
  }
}
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  int n;
  cin >> n;
  int k = n + 1;
  ll f[k];
  f[0] = f[1] = 1;
  for (int i = 2; i < k; i++)
    f[i] = (f[i - 1] * i) % hell;
  ll ans = 0, p = f[n];
  for (int i = 2; i <= n; i++) {
    ll a = ((power(f[i], hell - 2, hell)) * p) % hell;
    a = (a * power(f[n - i], hell - 2, hell)) % hell;
    ll z = ((power(2, 3 * n - 2 * i, hell) - power(2, 3 * n - 3 * i + 1, hell) +
             hell)) %
           hell;
    a = (a * z) % hell;
    ans = (ans + a) % hell;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z) {
  if (y == 0)
    return 1;
  else {
    ll p = power(x, y / 2, z);
    ll w = (p * p) % z;
    if (y % 2 == 0)
      return w;
    else
      return (x * w) % z;
  }
}
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  int n;
  cin >> n;
  int k = n + 1;
  ll f[k];
  f[0] = f[1] = 1;
  for (int i = 2; i < k; i++)
    f[i] = (f[i - 1] * i) % hell;
  ll ans = 0, p = f[n];
  for (int i = 2; i <= n; i++) {
    ll a = ((power((f[i] * f[n - i]) % hell, hell - 2, hell)) * p) % hell;
    ll z = ((power(2, 3 * n - 2 * i, hell) - power(2, 3 * n - 3 * i + 1, hell) +
             hell)) %
           hell;
    a = (a * z) % hell;
    ans = (ans + a) % hell;
  }
  cout << ans;
}
Problem p02555 (C++)

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

int main() {
  int S;
  cin >> S;
  vector<ll> ans(S + 1);
  // ans[i] = ans[i-3] + ans[i-4] + ... + ans[0]
  // ans[i-1] =          ans[i-4] + ... + ans[0]
  // ans[i] = ans[i-1] + ans[i-3]
  ans[3] = 1;
  for (int i = 4; i <= S; i++) {
    ans[i] = ans[i - 1] + ans[i - 3];
    ans[i] %= MOD;
  }
  cout << ans[S] << endl;
  return 0;
}

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

int main() {
  int S;
  cin >> S;
  if (S < 3) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> ans(S + 1);
  // ans[i] = ans[i-3] + ans[i-4] + ... + ans[0]
  // ans[i-1] =          ans[i-4] + ... + ans[0]
  // ans[i] = ans[i-1] + ans[i-3]
  ans[3] = 1;
  for (int i = 4; i <= S; i++) {
    ans[i] = ans[i - 1] + ans[i - 3];
    ans[i] %= MOD;
  }
  cout << ans[S] << endl;
  return 0;
}
Problem p02555 (C++)

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

const int MAX = 670;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}

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

const int MAX = 2000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}
Problem p02555 (C++)

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

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[s + 1];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

  return 0;
}

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

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[2005];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> dp(n + 1);
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= n; i++) {
    for (int j = 3; j <= i; j++) {
      dp[i] = (dp[i] + dp[i - j]) % mod;
    }
  }
  cout << dp[n];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> dp(n + 1);
  if (n < 3) {
    cout << "0";
    return 0;
  }
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= n; i++) {
    for (int j = 3; j <= i; j++) {
      dp[i] = (dp[i] + dp[i - j]) % mod;
    }
  }
  cout << dp[n];
}
Problem p02555 (C++)

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1, 0);
  rep(i, 3) {
    dp[i] = 0;
    dp[i + 3] = 1;
  }
  rep(i, s + 1) {
    if (0 <= i && i <= 5)
      continue;
    dp[i] = (dp[i - 1] + dp[i - 3]) % inf;
  }
  cout << dp[s] << endl;
  return 0;
}

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

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int s;
  cin >> s;
  if (s >= 0 && s <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (s >= 3 && s <= 5) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> dp(s + 1, 0);
  rep(i, 3) {
    dp[i] = 0;
    dp[i + 3] = 1;
  }
  rep(i, s + 1) {
    if (0 <= i && i <= 5)
      continue;
    dp[i] = (dp[i - 1] + dp[i - 3]) % inf;
  }
  cout << dp[s] << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 2, Mod = 1e9 + 7;
long long int dp[N];
int s;
long long calc(long long sum) {
  // cout<<1;
  if (sum == s)
    return 1;
  if (sum > s)
    return 0;
  long long &ret = dp[sum];
  if (ret != -1)
    return ret;
  ret = 0;
  bool z = 0, n = 0;
  for (int i = 3; i <= s; i++) {

    ret += calc(sum + i) % Mod;
    ret %= Mod;
  }
  return ret %= Mod;
}
int main() {
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << calc(0);
  // cout<<2;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2, Mod = 1e9 + 7;
long long int dp[N];
int s;
long long calc(long long sum) {
  // cout<<1;
  if (sum == s)
    return 1;
  if (sum > s)
    return 0;
  long long &ret = dp[sum];
  if (ret != -1)
    return ret;
  ret = 0;
  bool z = 0, n = 0;
  for (int i = 3; i <= s; i++) {

    ret += calc(sum + i) % Mod;
    ret %= Mod;
  }
  return ret %= Mod;
}
int main() {
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << calc(0);
  // cout<<2;
}
Problem p02555 (C++)

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll S;
  cin >> S;
  vector<ll> vec(S + 1);
  vec[0] = 0;
  vec[1] = 0;
  vec[2] = 0;
  vec[3] = 1;
  vec[4] = 1;
  vec[5] = 1;
  for (int i = 6; i <= S; ++i) {
    ll tmp = 1;
    for (int j = 3; j <= i - 3; ++j) {
      tmp += vec[j];
      tmp %= mod;
    }
    vec[i] = tmp;
  }

  cout << vec[S] << endl;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll S;
  cin >> S;
  vector<ll> vec(2001);
  vec[0] = 0;
  vec[1] = 0;
  vec[2] = 0;
  vec[3] = 1;
  vec[4] = 1;
  vec[5] = 1;
  for (int i = 6; i <= S; ++i) {
    ll tmp = 1;
    for (int j = 3; j <= i - 3; ++j) {
      tmp += vec[j];
      tmp %= mod;
    }
    vec[i] = tmp;
  }

  cout << vec[S] << endl;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

  if (s <= 2) {
    cout << 0 << endl;
    return;
  }
  if (s <= 5) {
    cout << 1 << endl;
    return;
  }

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}
Problem p02555 (C++)

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

int main() {
  ll s = 0;
  cin >> s;
  vector<ll> dp(s + 1, 0);
  dp[3] = 1;
  for (int i = 4; i <= s; i++)
    dp[i] = (dp[i - 1] + dp[i - 3]) % 1000000007;
  cout << dp[s] << endl;
  return 0;
}


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

int main() {
  ll s = 0;
  cin >> s;
  vector<ll> dp(2001, 0);
  dp[3] = 1;
  for (int i = 4; i <= s; i++)
    dp[i] = (dp[i - 1] + dp[i - 3]) % 1000000007;
  cout << dp[s] << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int s;
  cin >> s;
  vector<vector<in>> dp(s / 3, vector<in>(s + 1, 0));
  REP(i, 3, s + 1) dp[0][i] = 1;
  in ans = 0;
  ans += dp[0][s];

  for (int i = 1; i < s / 3; i++) {
    in sum = 0;
    REP(j, 3 * i + 3, s + 1) {
      sum += dp[i - 1][j - 3];
      sum %= MOD;
      dp[i][j] = sum;
    }
    ans += dp[i][s];
    ans %= MOD;
  }
  cout << ans << endl;
} /*
 ./problem.exe
 */

Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int s;
  cin >> s;
  vector<vector<in>> dp(max(s / 3, 1), vector<in>(s + 1, 0));
  REP(i, 3, s + 1) dp[0][i] = 1;
  in ans = 0;
  ans += dp[0][s];

  for (int i = 1; i < s / 3; i++) {
    in sum = 0;
    REP(j, 3 * i + 3, s + 1) {
      sum += dp[i - 1][j - 3];
      sum %= MOD;
      dp[i][j] = sum;
    }
    ans += dp[i][s];
    ans %= MOD;
  }
  cout << ans << endl;
} /*
 ./problem.exe
 */
Problem p02555 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<long> dp(N + 1, 0);
  dp.at(1) = 0;
  dp.at(2) = 0;
  dp.at(3) = 1;
  dp.at(4) = 1;
  dp.at(5) = 1;
  for (int i = 6; i <= N; i++) {
    // int l=i/2;
    for (int j = 3; j <= i - 3; j++) {
      dp.at(i) += dp.at(i - j);
      dp.at(i) %= 1000000007;
    }
    dp.at(i)++;
  }
  cout << dp.at(N) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<long> dp(N + 1, 0);
  for (int i = 3; i <= N; i++) {
    // int l=i/2;
    for (int j = 3; j <= i - 3; j++) {
      dp.at(i) += dp.at(i - j);
      dp.at(i) %= 1000000007;
    }
    dp.at(i)++;
  }
  cout << dp.at(N) << endl;
}
Problem p02555 (C++)

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

long calc(long n, vector<long> &dp, long mod) {
  if (n < 3)
    return 0;
  if (dp[n] != 0)
    return dp[n];
  for (int i = 3; i <= n; i++) {

    if (n != i)
      dp[n] += calc(n - i, dp, mod);
    else
      dp[n]++;
    dp[n] %= mod;
  }
  dp[n] %= mod;

  return dp[n];
}

int main() {
  long s;
  cin >> s;
  long const mod = 1e9 + 7;
  vector<long> dp(s + 1);
  dp[3] = 1;

  cout << calc(s, dp, mod) << endl;
}

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

long calc(long n, vector<long> &dp, long mod) {
  if (n < 3)
    return 0;
  if (dp[n] != 0)
    return dp[n];
  for (int i = 3; i <= n; i++) {

    if (n != i)
      dp[n] += calc(n - i, dp, mod);
    else
      dp[n]++;
    dp[n] %= mod;
  }
  dp[n] %= mod;

  return dp[n];
}

int main() {
  long s;
  cin >> s;
  long const mod = 1e9 + 7;
  vector<long> dp(s + 1);
  if (s >= 3)
    dp[3] = 1;

  cout << calc(s, dp, mod) << endl;
}
Problem p02555 (C++)

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

#define fi first
#define se second
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " is " << x << "\n";

using ll = long long;
using ii = pair<ll, ll>;

const int S = 2005;
const int N = 670;
const int MOD = 1e9 + 7;

ll dp[N][S];
int main() {
  int s;
  scanf("%d", &s);
  dp[0][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 3; j <= s; j++) {
      for (int k = 3; k <= j; k++) {
        dp[i][j] += dp[i - 1][j - k];
        if (dp[i][j] >= MOD)
          dp[i][j] -= MOD;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += dp[i][s];
    if (ans >= MOD)
      ans -= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " is " << x << "\n";

using ll = long long;
using ii = pair<ll, ll>;

const int S = 2005;
const int N = 670;
const int MOD = 1e9 + 7;

ll dp[N][S];
int main() {
  int s;
  scanf("%d", &s);
  dp[0][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 3; j <= s; j++) {
      // dp[i][j] = dp[i - 1][j - 3] + dp[i - 1][j - 4] + ... + dp[i - 1][0]
      // dp[i][j - 1] = dp[i - 1][j - 4] + dp[i - 1][j - 5] + ... + dp[i - 1][0]
      // dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 3];

      dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 3];
      if (dp[i][j] >= MOD)
        dp[i][j] -= MOD;

      // for(int k = 3; k <= j; k++) {
      //   dp[i][j] += dp[i - 1][j - k];
      //   if(dp[i][j] >= MOD) dp[i][j] -= MOD;
      // }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += dp[i][s];
    if (ans >= MOD)
      ans -= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02555 (C++)

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

int dp(int n, int m[]) {
  if (m[n - 3] == 0)
    dp(n - 3, m);
  if (m[n - 1] == 0)
    dp(n - 1, m);
  m[n] = (m[n - 3] + m[n - 1]) % 1000000007;
}

int main() {
  int nom[2000] = {
      0,
  };
  nom[3] = nom[4] = nom[5] = 1;
  int n;
  cin >> n;
  if (n < 6)
    cout << nom[n];
  else {
    dp(n, nom);
    cout << nom[n];
  }
}

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

int dp(int n, int m[]) {
  if (m[n - 3] == 0)
    dp(n - 3, m);
  if (m[n - 1] == 0)
    dp(n - 1, m);
  m[n] = (m[n - 3] + m[n - 1]) % 1000000007;
  return 0;
}

int main() {
  int nom[2000] = {
      0,
  };
  nom[3] = nom[4] = nom[5] = 1;
  int n;
  cin >> n;
  if (n < 6)
    cout << nom[n];
  else {
    dp(n, nom);
    cout << nom[n];
  }
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

ll move(ll n) {
  ll a[n + 1];
  a[0] = 1;
  a[1] = 0;
  a[2] = 0;
  a[3] = 1;

  for (int i = 4; i <= n; i++) {
    a[i] = (a[i - 1] + a[i - 3]) % MOD;
  }
  return a[n];
}

int main() {
  ll n;
  cin >> n;
  ans = move(n);
  cout << ans % MOD << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

ll move(ll n) {
  ll a[n + 10];
  a[0] = 1;
  a[1] = 0;
  a[2] = 0;
  a[3] = 1;

  for (int i = 4; i <= n; i++) {
    a[i] = (a[i - 1] + a[i - 3]) % MOD;
  }
  return a[n];
}

int main() {
  ll n;
  cin >> n;
  ans = move(n);
  cout << ans % MOD << endl;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll MOD = 1e9 + 7;
  int S;
  cin >> S;
  vector<ll> ans(S + 1, 0);
  ans[3] = 1;
  for (int i = 4; i <= S; i++) {
    ans[i] = (ans[i - 1] + ans[i - 3]) % MOD;
  }
  cout << ans[S] << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll MOD = 1e9 + 7;
  int S;
  cin >> S;
  vector<ll> ans(S + 1, 0);
  ans[0] = 1;
  for (int i = 3; i <= S; i++) {
    ans[i] = (ans[i - 1] + ans[i - 3]) % MOD;
  }
  cout << ans[S] << endl;
  return 0;
}
Problem p02555 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<long long> S(N);
  S.at(2) = 1;
  if (N >= 4) {
    for (int i = 3; i < N; i++) {
      S.at(i) = S.at(i - 1) + S.at(i - 3);
      S.at(i) %= 1000000007;
    }
  }
  cout << S.at(N - 1) << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<long long> S(N);
  if (N >= 3) {
    S.at(2) = 1;
    if (N >= 4) {
      for (int i = 3; i < N; i++) {
        S.at(i) = S.at(i - 1) + S.at(i - 3);
        S.at(i) %= 1000000007;
      }
    }
  }
  cout << S.at(N - 1) << endl;
  return 0;
}
Problem p02555 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;

ll solve(ll a) {
  if (a == 0) {
    return 1;
  } else if (a == 1 || a == 2) {
    return 0;
  } else if (a >= 3 && a <= 5) {
    return 1;
  } else {
    ll b = 0;
    for (ll i = a - 3; i >= 0; i--) {
      b = (b + solve(i)) % mod;
    }
    return b;
  }
}

int main() {
  ll s;
  cin >> s;
  vector<ll> ans(s + 1);
  rep(i, s + 1) { ans[i] = 0; }
  ans[0] = 1;
  ans[1] = 0;
  ans[2] = 0;
  ans[3] = 1;
  ans[4] = 1;
  ans[5] = 1;
  for (ll i = 6; i <= s; i++) {
    for (ll j = i - 3; j >= 0; j--) {
      ans[i] = (ans[i] + ans[j]) % mod;
    }
  }
  cout << ans[s] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;

ll solve(ll a) {
  if (a == 0) {
    return 1;
  } else if (a == 1 || a == 2) {
    return 0;
  } else if (a >= 3 && a <= 5) {
    return 1;
  } else {
    ll b = 0;
    for (ll i = a - 3; i >= 0; i--) {
      b = (b + solve(i)) % mod;
    }
    return b;
  }
}

int main() {
  ll s;
  cin >> s;
  vector<ll> ans(s + 10);
  rep(i, s + 10) { ans[i] = 0; }
  ans[0] = 1;
  ans[1] = 0;
  ans[2] = 0;
  ans[3] = 1;
  ans[4] = 1;
  ans[5] = 1;
  for (ll i = 6; i <= s; i++) {
    for (ll j = i - 3; j >= 0; j--) {
      ans[i] = (ans[i] + ans[j]) % mod;
    }
  }
  cout << ans[s] << endl;
}
Problem p02555 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll int
int const MOD = 1e9 + 7;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
ll sum;
ll cache[700][2001];
ll dp(int i, int s) {
  if (s > sum)
    return 0;
  if (s == sum)
    return 1;
  ll &ans = cache[i][s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 3; j <= sum; j++)
    ans += dp(i + 1, s + j), ans %= MOD;
  return ans % MOD;
}
int32_t main() {
  fastIO;
  memset(cache, -1, sizeof(cache));
  cin >> sum;
  ll ans = 0;
  for (int i = 3; i <= sum; i++)
    ans += dp(0, i), ans %= MOD;
  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll int
int const MOD = 1e9 + 7;
#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
ll sum;
ll cache[700][2001];
ll dp(int i, int s) {
  if (s > sum)
    return 0;
  if (s == sum)
    return 1;
  ll &ans = cache[i][s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 3; j <= sum - s; j++)
    ans += dp(i + 1, s + j), ans %= MOD;
  return ans % MOD;
}
int32_t main() {
  fastIO;
  memset(cache, -1, sizeof(cache));
  cin >> sum;
  ll ans = 0;
  for (int i = 3; i <= sum; i++)
    ans += dp(0, i), ans %= MOD;
  cout << ans;

  return 0;
}
Problem p02555 (C++)

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

const int mod = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1);

  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= mod;
  }
  cout << dp[s];
}


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

const int mod = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1);

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= mod;
  }
  cout << dp[s];
}