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

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

typedef long long int ll;
#define rep(i, n) for (i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i < n; ++i)
#define REPR(i, k, n) for (i = k; i >= n; --i)
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define N 300101
#define SZ 3001
#define LB lower_bound
#define M 1000000007
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second

typedef vector<long long int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (auto i = c.begin(); i != c.end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c),x) != (c).end()
#define flash                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL), cout.tie(NULL);

int main() {
  flash
#ifndef ONLINE_JUDGE
      freopen("inp", "r", stdin);
#else
// online submission
#endif

  ll p, q, r;
  cin >> p >> q >> r;

  ll max = p + q;
  if (max > q + r) {
    max = q + r;
  }
  if (max > r + p) {
    max = r + p;
  }

  cout << max << endl;
}


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

typedef long long int ll;
#define rep(i, n) for (i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i < n; ++i)
#define REPR(i, k, n) for (i = k; i >= n; --i)
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define N 300101
#define SZ 3001
#define LB lower_bound
#define M 1000000007
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second

typedef vector<long long int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (auto i = c.begin(); i != c.end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c),x) != (c).end()
#define flash                                                                  \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL), cout.tie(NULL);

int main() {

  ll p, q, r;
  cin >> p >> q >> r;

  ll max = p + q;
  if (max > q + r) {
    max = q + r;
  }
  if (max > r + p) {
    max = r + p;
  }

  cout << max << endl;
}
Problem p03011 (C++)

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

int main(void) {
  int p, q, r, a;
  cin >> p >> q >> r;
  a = min(p + q, q + r);
  a = min(a, p + r);
  cout << a << endl;
  return 1;
}

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

int main(void) {
  int p, q, r, a;
  cin >> p >> q >> r;
  a = min(p + q, q + r);
  a = min(a, p + r);
  cout << a << endl;
  return 0;
}
Problem p03011 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> fl;
  for (int i = 0; i < 3; i++) {
    cin >> fl.at(i);
  }
  sort(fl.begin(), fl.end());
  cout << fl.at(0) + fl.at(1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> fl(3);
  for (int i = 0; i < 3; i++) {
    cin >> fl.at(i);
  }
  sort(fl.begin(), fl.end());
  cout << fl.at(0) + fl.at(1) << endl;
}
Problem p03011 (C++)

Buggy submission (status: Runtime Error):
// https://atcoder.jp/contests/abc129/tasks/abc129_a
#include <bits/stdc++.h>
#define debugi(x) cerr << "x -> " << x << endl;
#define For(i, n) for (__typeof(i) i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

void solve() {
  int i;
  vector<int> flight_times(3, INT_MAX);
  For(i, 3) { cin >> flight_times[i]; }
  sort(all(flight_times));
  cout << flight_times[0] + flight_times[1] << endl;
}
int main() {
  _;
  ull testcases = 1LL;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // cin >> testcases;
  while (testcases--)
    solve();
  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/abc129/tasks/abc129_a
#include <bits/stdc++.h>
#define debugi(x) cerr << "x -> " << x << endl;
#define For(i, n) for (__typeof(i) i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

void solve() {
  int i;
  vector<int> flight_times(3, INT_MAX);
  For(i, 3) { cin >> flight_times[i]; }
  sort(all(flight_times));
  cout << flight_times[0] + flight_times[1] << endl;
}
int main() {
  _;
  ull testcases = 1LL;
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  // cin >> testcases;
  while (testcases--)
    solve();
  return 0;
}
Problem p03012 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cstdio>

using namespace std;

int n;
int w[101];

int main(void) {
  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
  }

  int m = INT_MAX;
  int s1, s2;

  for (int t = 1; t < n; t++) {
    s1 = 0;
    for (int i = 1; i <= t; i++) {
      s1 += w[i];
    }

    s2 = 0;
    for (int i = t + 1; t < n; i++) {
      s2 += w[i];
    }

    m = min(m, abs(s1 - s2));
  }

  printf("%d\n", m);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdio>

using namespace std;

int n;
int w[101];

int main(void) {
  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
  }

  int m = INT_MAX;
  int s1, s2;

  for (int t = 1; t < n; t++) {
    s1 = 0;
    for (int i = 1; i <= t; i++) {
      s1 += w[i];
    }

    s2 = 0;
    for (int i = t + 1; i <= n; i++) {
      s2 += w[i];
    }

    m = min(m, abs(s1 - s2));
  }

  printf("%d\n", m);

  return 0;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> w(n, 0), s(n, 0);
  for (int i = 1; i < n + 1; ++i) {
    cin >> w[i];
    s[i] = s[i - 1] + w[i];
  }

  int mn = 1e9;
  for (int i = 1; i < n; ++i) {
    mn = min(mn, abs(s[n] - 2 * s[i]));
  }
  cout << mn << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> w(n + 1, 0), s(n + 1, 0);
  for (int i = 1; i < n + 1; ++i) {
    cin >> w[i];
    s[i] = s[i - 1] + w[i];
  }

  int mn = 1e9;
  for (int i = 1; i < n; ++i) {
    mn = min(mn, abs(s[n] - 2 * s[i]));
  }
  cout << mn << endl;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>

const double pi = 3.14159265358979323846264;
const int mod = 1000000007;

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  // std::cout << std::fixed;
  // std::cout << std::setprecision(12);
  // std::cout << std::defaultfloat;
  int n;
  cin >> n;
  vector<int> w(n);
  FOR(i, 0, n) cin >> w[i];
  int ans = mod, ss = 0;
  w[n] = 0;
  FOR(i, 0, n) ss += w[i];
  FOR(i, 0, n + 1) {
    int s = 0;
    FOR(j, 0, i) { s += w[j]; }
    int t = abs(ss - s - s);
    ans = min(ans, t);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>

const double pi = 3.14159265358979323846264;
const int mod = 1000000007;

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  // std::cout << std::fixed;
  // std::cout << std::setprecision(12);
  // std::cout << std::defaultfloat;
  int n;
  cin >> n;
  vector<int> w(n + 1, 0);
  FOR(i, 0, n) cin >> w[i];
  int ans = mod, ss = 0;
  w[n] = 0;
  FOR(i, 0, n) ss += w[i];
  FOR(i, 0, n + 1) {
    int s = 0;
    FOR(j, 0, i) { s += w[j]; }
    int t = abs(ss - s - s);
    ans = min(ans, t);
  }
  cout << ans << endl;

  return 0;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> accum(n + 1); // 累積和
  vector<int> w(n);

  accum[0] = 0;
  rep(i, n) cin >> w.at(i);

  for (int i = 1; i < n + 1; i++) {
    accum.at(i) = accum.at(i - 1) + w.at(i);
  }

  int ans = 1e9;
  rep(i, n) { ans = min(ans, abs(accum.at(n) - 2 * accum.at(i))); }
  cout << ans << endl;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> accum(n + 1); // 累積和
  vector<int> w(n);

  accum[0] = 0;
  rep(i, n) cin >> w.at(i);

  for (int i = 1; i < n + 1; i++) {
    accum.at(i) = accum.at(i - 1) + w.at(i - 1);
  }

  int ans = 1e9;
  rep(i, n) { ans = min(ans, abs(accum.at(n) - 2 * accum.at(i))); }
  cout << ans << endl;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 1; i <= N; i++) {
    cin >> W.at(i);
  }
  int ans = 1e9;
  for (int i = 1; i < N; i++) {
    int l = 0, r = 0;
    for (int j = 0; j < i; j++) {
      l += W.at(j);
    }
    for (int j = i; j < N; j++) {
      r += W.at(j);
    }
    ans = min(ans, abs(l - r));
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  int ans = 1e9;
  for (int i = 1; i < N; i++) {
    int l = 0, r = 0;
    for (int j = 0; j < i; j++) {
      l += W.at(j);
    }
    for (int j = i; j < N; j++) {
      r += W.at(j);
    }
    ans = min(ans, abs(l - r));
  }
  cout << ans << endl;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  rep(i, N) cin >> W[i];

  vector<int> s(N + 1, 0);
  rep(i, N + 1) s[i + 1] = s[i] + W[i];
  ll ans = INF;
  for (int t = 0; t < N; ++t) {
    ll s1 = s[t + 1];
    ll s2 = s[N] - s[t + 1];
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  rep(i, N) cin >> W[i];

  vector<int> s(N + 1, 0);
  rep(i, N) s[i + 1] = s[i] + W[i];
  ll ans = INF;
  for (int t = 0; t < N; ++t) {
    ll s1 = s[t + 1];
    ll s2 = s[N] - s[t + 1];
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int absolute(int a);
int main() {
  int N, i, ans = 10010;
  cin >> N;
  vector<int> W(N), sum(N);
  for (i = 0; i < N; i++)
    cin >> W[i];
  sum[0] = W[0];
  for (i = 0; i < N; i++)
    sum[i + 1] = sum[i] + W[i + 1];
  for (i = 0; i < N; i++) {
    if (ans > absolute(2 * sum[i] - sum[N - 1]))
      ans = absolute(2 * sum[i] - sum[N - 1]);
  }
  cout << ans << endl;
}
int absolute(int a) {
  if (a < 0)
    return -a;
  else
    return a;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int absolute(int a);
int main() {
  int N, i, ans = 10010;
  cin >> N;
  vector<int> W(N), sum(N);
  for (i = 0; i < N; i++)
    cin >> W[i];
  sum[0] = W[0];
  for (i = 0; i < N - 1; i++)
    sum[i + 1] = sum[i] + W[i + 1];
  for (i = 0; i < N; i++) {
    if (ans > absolute(2 * sum[i] - sum[N - 1]))
      ans = absolute(2 * sum[i] - sum[N - 1]);
  }
  cout << ans << endl;
}
int absolute(int a) {
  if (a < 0)
    return -a;
  else
    return a;
}
Problem p03012 (C++)

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

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

int main() {
  int N;
  cin >> N;
  vector<int> ts;
  ts.push_back(0);
  int w;
  for (int i = 1; i <= N; ++i) {
    cin >> w;
    ts[i] = ts[i - 1] + w;
  }
  int ans = 1000000;
  for (int t = 1; t < N; ++t) {
    int s1 = ts[t];
    int s2 = ts[N] - ts[t];
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}

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

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

int main() {
  int N;
  cin >> N;
  vector<int> ts(N + 1);
  ts[0] = 0;
  int w;
  for (int i = 1; i <= N; ++i) {
    cin >> w;
    ts[i] = ts[i - 1] + w;
  }
  int ans = 1000000;
  for (int t = 1; t < N; ++t) {
    int s1 = ts[t];
    int s2 = ts[N] - ts[t];
    chmin(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}
Problem p03012 (C++)

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

int now, n, k;

int main() {
  int ans = 999999999;
  cin >> n;
  vector<int> a(n), csum(n + 1, 0);
  REP(i, n) cin >> a[i];
  REP(i, n + 1) csum[i + 1] = csum[i] + a[i];

  REP(i, n - 1) ans = min(ans, abs(csum[n] - csum[i + 1] - csum[i + 1]));
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define MOD 1000000007

int now, n, k;

int main() {
  int ans = 999999999;
  cin >> n;
  vector<int> a(n), csum(n + 1, 0);
  REP(i, n) cin >> a[i];
  REP(i, n) csum[i + 1] = csum[i] + a[i];

  REP(i, n - 1) ans = min(ans, abs(csum[n] - csum[i + 1] - csum[i + 1]));
  cout << ans << endl;

  return 0;
}
Problem p03012 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main(void) {
  int N, ans;
  scanf("%d", &N);
  vector<int> W(N);
  int Sum = 0;
  REP(int, i, 0, N) {
    scanf("%lld", &W.at(i));
    Sum += W.at(i);
  }
  ans = INT_MAX;
  int Sum2 = Sum;
  REP(int, i, 0, N) {
    Sum2 -= W.at(i);
    int Sum1 = Sum - Sum2;
    int Diff = abs(Sum1 - Sum2);
    ans = min(ans, Diff);
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;

using namespace std;

int main(void) {
  int N, ans;
  scanf("%d", &N);
  vector<int> W(N);
  int Sum = 0;
  REP(int, i, 0, N) {
    scanf("%d", &W.at(i));
    Sum += W.at(i);
  }
  ans = INT_MAX;
  int Sum2 = Sum;
  REP(int, i, 0, N) {
    Sum2 -= W.at(i);
    int Sum1 = Sum - Sum2;
    int Diff = abs(Sum1 - Sum2);
    ans = min(ans, Diff);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03012 (C++)

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

int main() {
  int n, i, sum = 0, keep = 0, a, b;
  cin >> n;

  vector<int> w(n), x(n - 1);
  for (i = 0; i < n; i++) {
    cin >> w.at(i);
    sum += w.at(i);
  }

  for (i = 0; i < n; i++) {
    keep += w.at(i);
    x.at(i) = abs(sum - 2 * keep);
  }

  sort(x.begin(), x.end());

  cout << x.at(0) << endl;
}


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

int main() {
  int n, i, sum = 0, keep = 0, a, b;
  cin >> n;

  vector<int> w(n), x(n);
  for (i = 0; i < n; i++) {
    cin >> w.at(i);
    sum += w.at(i);
  }

  for (i = 0; i < n; i++) {
    keep += w.at(i);
    x.at(i) = abs(sum - 2 * keep);
  }

  sort(x.begin(), x.end());

  cout << x.at(0) << endl;
}
Problem p03012 (Python)

Buggy submission (status: Runtime Error):
N = input()
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))


Fixed submission:
N = int(input())
W = list(map(int, input().split()))
print(min([abs(sum(W[:i]) - sum(W[i:])) for i in range(N)]))
Problem p03013 (C++)

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

int main() {
  int n, m, a;
  cin >> n >> m;
  vector<bool> br(m);
  vector<ll> dp(n + 1, 0);
  for (int i = 0; i < m; i++) {
    cin >> a;
    br[a] = true;
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (i + 1 <= n && !br[i + 1])
      dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    if (i + 2 <= n && !br[i + 2])
      dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
  }
  cout << dp[n] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = (1e+9) + 7;

int main() {
  int n, m, a;
  cin >> n >> m;
  vector<bool> br(n + 1, false);
  vector<ll> dp(n + 1, 0);
  for (int i = 0; i < m; i++) {
    cin >> a;
    br[a] = true;
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    if (i + 1 <= n && !br[i + 1])
      dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    if (i + 2 <= n && !br[i + 2])
      dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
  }
  cout << dp[n] << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD ((ll)1e9 + 7)

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }

  vector<ll> dan(N + 1);
  dan[0] = 1;
  int j = 0;
  for (int i = 1; i < N + 1; i++) {
    if (i == a[j]) {
      if (dan[i - 1] == 0) {
        cout << 0;
        return 0;
      } else {
        dan[i] = 0;
      }

      if (j < M - 1) {
        j++;
      }
    } else {
      if (i == 1) {
        dan[i] = dan[i - 1];
      } else {
        dan[i] = dan[i - 1] + dan[i - 2];
      }
    }
    dan[i] %= MOD;
  }
  cout << dan[N];
  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD ((ll)1e9 + 7)

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> a(100001, 0);
  if (M != 0) {
    for (int i = 0; i < M; i++) {
      cin >> a[i];
    }
  }

  vector<ll> dan(N + 1);
  dan[0] = 1;
  int j = 0;
  for (int i = 1; i < N + 1; i++) {
    if (i == a[j]) {
      if (dan[i - 1] == 0) {
        cout << 0;
        return 0;
      } else {
        dan[i] = 0;
      }

      if (j < M - 1) {
        j++;
      }
    } else {
      if (i == 1) {
        dan[i] = dan[i - 1];
      } else {
        dan[i] = dan[i - 1] + dan[i - 2];
      }
    }
    dan[i] %= MOD;
  }
  cout << dan[N];
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> oks(N + 1, true);
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    oks[a] = false;
  }

  vector<long long int> dp(N + 1);
  dp[0] = 1;
  for (int now = 0; now < N; now++) {
    for (int next = now + 1; now < min(N, now + 2); next++) {
      if (oks[next]) {
        dp[next] += dp[now];
        dp[next] %= mod;
      }
    }
  }

  cout << dp[N] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> oks(N + 1, true);
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    oks[a] = false;
  }

  vector<long long int> dp(N + 1);
  dp[0] = 1;
  for (int now = 0; now < N; now++) {
    for (int next = now + 1; next <= min(N, now + 2); next++) {
      if (oks[next]) {
        dp[next] += dp[now];
        dp[next] %= mod;
      }
    }
  }

  cout << dp[N] << endl;
  return 0;
}
Problem p03013 (C++)

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

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  vector<int> a;
  int box;

  int sum = 0;
  int pre_1 = 1;
  int pre_2 = 1;

  int cnt = 0;

  int i;
  for (i = 0; i < m; i++) {
    cin >> box;
    a.push_back(box);
    // cout << a[i] << endl;
  }

  for (i = 0; i <= n; i++) {
    // cout << "i = " << i << endl;
    if (i == 0 || i == 1) {
      // 階段1が穴だった時
      if (a[cnt] == i) {

        sum = 1;
        pre_1 = 0;

        if (cnt < m)
          cnt++;
      } else {

        sum = 1;
        pre_1 = 1;
      }
    } else {
      if (a[cnt] == i) {
        if (pre_1 == 0) {

          sum = 0;
          break;
        }

        // sum = 0;
        pre_2 = pre_1;
        pre_1 = 0;

        if (cnt < m)
          cnt++;
        // cout << "i = " << i << endl;
      } else {
        sum = (pre_1 + pre_2) % 1000000007;
        pre_2 = pre_1;
        pre_1 = sum;
      }
    }

    // cout << "sum = " << sum << endl;
  }
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  vector<int> a;
  int box;

  int sum = 0;
  int pre_1 = 1;
  int pre_2 = 1;

  int cnt = 0;

  int i;
  if (m != 0) {
    for (i = 0; i < m; i++) {

      cin >> box;
      a.push_back(box);
      // cout << a[i] << endl;
    }
  } else {
    a.push_back(-1);
  }

  for (i = 0; i <= n; i++) {
    // cout << "i = " << i << endl;
    if (i == 0 || i == 1) {
      // 階段1が穴だった時
      if (a[cnt] == i) {

        sum = 1;
        pre_1 = 0;

        if (cnt < m)
          cnt++;
      } else {

        sum = 1;
        pre_1 = 1;
      }
    } else {
      if (a[cnt] == i) {
        if (pre_1 == 0) {

          sum = 0;
          break;
        }

        // sum = 0;
        pre_2 = pre_1;
        pre_1 = 0;

        if (cnt < m)
          cnt++;
        // cout << "i = " << i << endl;
      } else {
        sum = (pre_1 + pre_2) % 1000000007;
        pre_2 = pre_1;
        pre_1 = sum;
      }
    }

    // cout << "sum = " << sum << endl;
  }
  cout << sum << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<bool> ok(n + 1, true);
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    ok[a] = false;
  }

  vector<ll> dp(n + 1);
  dp[0] = 1;

  for (int i = 0; i < n; ++i) {
    if (ok[i + 1]) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD_LL;
    }

    if (ok[i + 2]) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD_LL;
    }
  }

  cout << dp[n] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<bool> ok(n + 1, true);
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    ok[a] = false;
  }

  vector<ll> dp(100005);
  dp[0] = 1;

  for (int i = 0; i < n; ++i) {
    if (ok[i + 1]) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD_LL;
    }

    if (ok[i + 2]) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD_LL;
    }
  }

  cout << dp[n] << endl;

  return 0;
}
Problem p03013 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<bool> b(N + 1, true);
  for (int i = 0; i < M + 1; i++) {
    int a;
    cin >> a;
    b.at(a) = false;
  }

  vector<int> dp(N + 1, 0);
  dp.at(0) = 1;
  int mod = 1000000007;
  if (b.at(1))
    dp.at(1) = 1;
  for (int i = 2; i < N + 1; i++) {
    if (b.at(i))
      dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % mod;
  }

  cout << dp.at(N) << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;

  vector<bool> b(N + 1, true);
  for (int i = 0; i < M + 1; i++) {
    int a;
    cin >> a;
    b.at(a) = false;
  }

  vector<int> dp(N + 1, 0);
  dp.at(0) = 1;
  int mod = 1000000007;
  if (b.at(1))
    dp.at(1) = 1;
  for (int i = 2; i < N + 1; i++) {
    if (b.at(i))
      dp.at(i) = (dp.at(i - 1) + dp.at(i - 2));
    dp.at(i) %= mod;
  }

  cout << dp.at(N) << endl;
}
Problem p03013 (C++)

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

const long long MOD = 1000000007;

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(M);
  for (int i = 0; i < M; i++)
    cin >> a[i];

  long long step[100010] = {};
  // i段目までの数
  step[0] = 1;
  for (int i = 1; i <= N; i++) {
    if (i == 1) {
      if (M > 0) {
        if (a[0] != 1) {
          step[i] = step[0];
        }
      } else {
        step[i] = step[0];
      }
    } else if (find(a.begin(), a.end(), i) == a.end()) {
      step[i] = (step[i - 1] + step[i - 2]) % MOD;
    }
  }
  cout << step[N] << endl;
}

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

const long long MOD = 1000000007;

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> a(M);
  for (int i = 0; i < M; i++)
    cin >> a[i];

  long long step[100010] = {};
  // i段目までの数
  step[0] = 1;
  for (int i = 1; i <= N; i++) {
    if (i == 1) {
      if (M > 0) {
        if (a[0] != 1) {
          step[i] = step[0];
        }
      } else {
        step[i] = step[0];
      }
    } else if (binary_search(a.begin(), a.end(), i) == false) {
      step[i] = (step[i - 1] + step[i - 2]) % MOD;
    }
  }
  cout << step[N] << endl;
}
Problem p03013 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<bool> broken(n + 1, false);
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    broken[a] = true;
  }
  vector<long long> count(n + 1, 0LL);
  count[0] = 1LL;
  count[1] = broken[1] ? 0LL : 1LL;
  for (int i = 2; i <= n; --i) {
    if (broken[i]) {
      count[i] = 0;
    } else {
      count[i] = (count[i - 1] + count[i - 2]) % 1000000007;
    }
  }
  cout << count[n] << endl;
  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<bool> broken(n + 1, false);
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    broken[a] = true;
  }
  vector<long long> count(n + 1, 0LL);
  count[0] = 1LL;
  count[1] = broken[1] ? 0LL : 1LL;
  for (int i = 2; i <= n; ++i) {
    if (broken[i]) {
      count[i] = 0;
    } else {
      count[i] = (count[i - 1] + count[i - 2]) % 1000000007;
    }
  }
  cout << count[n] << endl;
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
// const int MOD = 998244353;
// const int MOD = ;
int mod(int A, int M) { return (A % M + M) % M; }
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }

vector<int> memof(100100, 0);
int f(int N) {
  if (N == 0)
    return 1;
  if (N == 1)
    return 1;
  if (memof.at(N) > 0)
    return memof.at(N);
  int r = (f(N - 2) + f(N - 1)) % MOD;
  memof.at(N) = r;
  return r;
}

signed main() {
  int N, M;
  cin >> N >> M;

  int ans = 1;
  int a0 = -1;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    ans *= f(a - a0 - 2);
    ans %= MOD;
    a0 = a;
  }
  ans *= f(N - a0 - 1);
  ans %= MOD;

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
// const int MOD = 998244353;
// const int MOD = ;
int mod(int A, int M) { return (A % M + M) % M; }
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }

vector<int> memof(100100, 0);
int f(int N) {
  if (N < 0)
    return 0;
  if (N == 0)
    return 1;
  if (N == 1)
    return 1;
  if (memof.at(N) > 0)
    return memof.at(N);
  int r = (f(N - 2) + f(N - 1)) % MOD;
  memof.at(N) = r;
  return r;
}

signed main() {
  int N, M;
  cin >> N >> M;

  int ans = 1;
  int a0 = -1;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    ans *= f(a - a0 - 2);
    ans %= MOD;
    a0 = a;
  }
  ans *= f(N - a0 - 1);
  ans %= MOD;

  cout << ans << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> dp(n + 1);
  rep(i, m) cin >> a[i];
  int j = 0;
  dp[0] = 1;
  if (a[0] == 1)
    j++;
  else
    dp[1] = 1;
  FOR(i, 2, n + 1) {
    if (i == a[j]) {
      j++;
      continue;
    }
    dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }
  cout << dp[n] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m + 1);
  vector<int> dp(n + 1);
  rep(i, m) cin >> a[i];
  int j = 0;
  dp[0] = 1;
  if (a[0] == 1)
    j++;
  else
    dp[1] = 1;
  FOR(i, 2, n + 1) {
    if (i == a[j]) {
      j++;
      continue;
    }
    dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
  }
  cout << dp[n] << endl;
}
Problem p03013 (C++)

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

using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) {
      return 1;
    }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) {
      a *= *this;
    }
    return a;
  }

  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> as(m, false);
  rep(i, m) {
    int a;
    cin >> a;
    as[a] = true;
  };
  vector<mint> dp(n + 2, 0);
  dp[0] = 1;
  rep(i, n) {
    if (!as[i + 1]) {
      dp[i + 1] += dp[i];
    }
    if (!as[i + 2]) {
      dp[i + 2] += dp[i];
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) {
      x -= mod;
    }
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) {
      return 1;
    }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) {
      a *= *this;
    }
    return a;
  }

  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> as(n, false);
  rep(i, m) {
    int a;
    cin >> a;
    as[a] = true;
  };
  vector<mint> dp(n + 2, 0);
  dp[0] = 1;
  rep(i, n) {
    if (!as[i + 1]) {
      dp[i + 1] += dp[i];
    }
    if (!as[i + 2]) {
      dp[i + 2] += dp[i];
    }
  }
  cout << dp[n] << endl;
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (int(i) = 1; (i) < (n); ++(i))
#define rrep1(i, n) for (int(i) = (n)-1; (i) >= 1; --(i))
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(), (x).end()

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

int main() {
  ll n, m, cnt = 0;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0), a(m);
  rep0(i, m) cin >> a[i];
  dp[0] = 1;
  if (a[cnt] == 1) {
    dp[1] = 0;
    ++cnt;
  } else {
    dp[1] = 1;
  }
  nfor(i, 2, n + 1) {
    if (a[cnt] == i) {
      dp[i] = 0;
      ++cnt;
    } else {
      dp[i] = dp[i - 1] + dp[i - 2];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep0(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define rep1(i, n) for (int(i) = 1; (i) < (n); ++(i))
#define rrep1(i, n) for (int(i) = (n)-1; (i) >= 1; --(i))
#define nfor(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(), (x).end()

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

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

int main() {
  ll n, m, cnt = 0;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0), a(m + 1, 0);
  rep0(i, m) cin >> a[i];
  dp[0] = 1;
  if (a[cnt] == 1) {
    dp[1] = 0;
    ++cnt;
  } else {
    dp[1] = 1;
  }
  nfor(i, 2, n + 1) {
    if (a[cnt] == i) {
      dp[i] = 0;
      ++cnt;
    } else {
      dp[i] = dp[i - 1] + dp[i - 2];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
Problem p03013 (C++)

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

const int MOD = 1e+9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < M; ++i)
    cin >> a[i];

  sort(a.begin(), a.end());

  vector<long long> dp(N + 1);
  dp[0] = 1;

  int idx;
  if (a[0] == 1) {
    dp[1] = 0;
    idx = 1;
  } else {
    dp[1] = 1;
    idx = 0;
  }
  for (int i = 2; i <= N; ++i) {
    if (idx < M and i == a[idx]) {
      dp[i] = 0;
      ++idx;
    } else {
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
  }
  cout << dp[N] << endl;

  return 0;
}

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

const int MOD = 1e+9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < M; ++i)
    cin >> a[i];

  sort(a.begin(), a.end());

  vector<long long> dp(N + 1);
  dp[0] = 1;

  int idx;
  if (M > 0 and a[0] == 1) {
    dp[1] = 0;
    idx = 1;
  } else {
    dp[1] = 1;
    idx = 0;
  }
  for (int i = 2; i <= N; ++i) {
    if (idx < M and i == a[idx]) {
      dp[i] = 0;
      ++idx;
    } else {
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
  }
  cout << dp[N] << endl;

  return 0;
}
Problem p03013 (C++)

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

#include <iostream>
#include <vector>
using namespace std;

// 重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start,
                 const ll range_end) {
  if (i == size) {
    // ここで所望の作業を行う
    for (ll itr : buf) {
      cout << itr;
    }
  } else {
    for (ll j = range_start; j <= range_end; ++j) {
      buf[i] = j;
      permutation(i + 1, size, range_start, range_end);
    }
  }
}
int main(void) {
  ll n, m, a;
  ll mod = pow(10, 9) + 7;
  cin >> n >> m;
  vector<ll> A(n + 1);
  A[0] = 1;
  RAP(i, n) {
    cin >> a;
    A[a] = -1;
  }
  for (ll i = 1; i <= n; i++) {
    if (A[i] == -1) {
      continue;
    }
    if (i == 1) {
      A[i] = A[i - 1];
      continue;
    }
    if (A[i - 1] == -1 && A[i - 2] == -1) {
      break;
    } else if (A[i - 1] == -1) {
      A[i] = A[i - 2];
    } else if (A[i - 2] == -1) {
      A[i] = A[i - 1];
    } else {
      A[i] = (A[i - 1] + A[i - 2]) % mod;
    }
  }

  cout << A[n] << endl;
  return 0;
}


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

#include <iostream>
#include <vector>
using namespace std;

// 重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start,
                 const ll range_end) {
  if (i == size) {
    // ここで所望の作業を行う
    for (ll itr : buf) {
      cout << itr;
    }
  } else {
    for (ll j = range_start; j <= range_end; ++j) {
      buf[i] = j;
      permutation(i + 1, size, range_start, range_end);
    }
  }
}
int main(void) {
  ll n, m, a;
  ll mod = pow(10, 9) + 7;
  cin >> n >> m;
  vector<ll> A(n + 1);
  A[0] = 1;
  RAP(i, m) {
    cin >> a;
    A[a] = -1;
  }
  for (ll i = 1; i <= n; i++) {
    if (A[i] == -1) {
      continue;
    }
    if (i == 1) {
      A[i] = A[i - 1];
      continue;
    }
    if (A[i - 1] == -1 && A[i - 2] == -1) {
      break;
    } else if (A[i - 1] == -1) {
      A[i] = A[i - 2];
    } else if (A[i - 2] == -1) {
      A[i] = A[i - 1];
    } else {
      A[i] = (A[i - 1] + A[i - 2]) % mod;
    }
  }

  cout << A[n] << endl;
  return 0;
}
Problem p03013 (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, m;
  cin >> n >> m;
  vector<int> broken(n + 1);
  rep(i, m) {
    int a;
    cin >> a;
    broken[a] = 1;
  }

  vector<int> dp(n + 2);
  const int mod = 1e9 + 7;
  dp[n] = 1;
  for (int i = n - 1; i >= 0; i++) {
    if (broken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << 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, m;
  cin >> n >> m;
  vector<int> broken(n + 1);
  rep(i, m) {
    int a;
    cin >> a;
    broken[a] = 1;
  }

  vector<int> dp(n + 2);
  const int mod = 1e9 + 7;
  dp[n] = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (broken[i]) {
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << endl;
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
using namespace std;

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main(void) {
  int N, M;

  cin >> N >> M;

  vector<int> a(M), dp(N + 1, 0);

  for (auto &i : a)
    cin >> i;

  dp[N] = 1;
  if (a.back() != N - 1)
    dp[N - 1] = 1;
  for (int n = N - 2; n >= 0; n--) {
    if (!binary_search(a.begin(), a.end(), n)) {
      dp[n] = (dp[n + 1] + dp[n + 2]) % 1000000007;
    }
  }

  cout << dp[0] << endl;

  return 0;
}


Fixed submission:
using namespace std;

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main(void) {
  int N, M;

  cin >> N >> M;

  vector<int> a(M), dp(N + 1, 0);

  for (auto &i : a)
    cin >> i;

  dp[N] = 1;
  if (a.empty() || a.back() != N - 1)
    dp[N - 1] = 1;
  for (int n = N - 2; n >= 0; n--) {
    if (!binary_search(a.begin(), a.end(), n)) {
      dp[n] = (dp[n + 1] + dp[n + 2]) % 1000000007;
    }
  }

  cout << dp[0] << endl;

  return 0;
}