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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <float.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define ll long long

int main(void) {
  vector<ll> fib(100000);
  for (ll i = 0; i < 100000; i++) {
    if (i == 0)
      fib.at(0) = 1;
    else if (i == 1)
      fib.at(1) = 1;
    else
      fib.at(i) = (fib.at(i - 1) + fib.at(i - 2)) % 1000000007;
  }
  ll N, M, ans = 1;
  cin >> N >> M;
  if (M == 0) {
    cout << fib.at(N) << endl;
    return 0;
  }
  vector<ll> broken(M), ret(M + 1);
  for (ll i = 0; i < M; i++)
    cin >> broken.at(i);
  for (ll i = 0; i < M + 1; i++) {
    if (i == 0)
      ret.at(0) = broken.at(0) - 1;
    else if (i == M)
      ret.at(M) = N - broken.at(M - 1) - 1;
    else {
      ret.at(i) = broken.at(i) - broken.at(i - 1) - 2;
      if (ret.at(i) == -1) {
        cout << 0 << endl;
        return 0;
      } else if (ret.at(i) == -2)
        ret.at(i) = 0;
    }
  }
  for (ll i = 0; i < 100000; i++) {
    if (i == 0)
      fib.at(0) = 1;
    else if (i == 1)
      fib.at(1) = 1;
    else
      fib.at(i) = (fib.at(i - 1) + fib.at(i - 2)) % 1000000007;
  }

  for (ll i = 0; i < M + 1; i++)
    ans = (ans * fib.at(ret.at(i))) % 1000000007;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <float.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define ll long long

int main(void) {
  vector<ll> fib(100001);
  for (ll i = 0; i < 100001; i++) {
    if (i == 0)
      fib.at(0) = 1;
    else if (i == 1)
      fib.at(1) = 1;
    else
      fib.at(i) = (fib.at(i - 1) + fib.at(i - 2)) % 1000000007;
  }
  ll N, M, ans = 1;
  cin >> N >> M;
  if (M == 0) {
    cout << fib.at(N) << endl;
    return 0;
  }
  vector<ll> broken(M), ret(M + 1);
  for (ll i = 0; i < M; i++)
    cin >> broken.at(i);
  for (ll i = 0; i < M + 1; i++) {
    if (i == 0)
      ret.at(0) = broken.at(0) - 1;
    else if (i == M)
      ret.at(M) = N - broken.at(M - 1) - 1;
    else {
      ret.at(i) = broken.at(i) - broken.at(i - 1) - 2;
      if (ret.at(i) == -1) {
        cout << 0 << endl;
        return 0;
      } else if (ret.at(i) == -2)
        ret.at(i) = 0;
    }
  }
  for (ll i = 0; i < 100000; i++) {
    if (i == 0)
      fib.at(0) = 1;
    else if (i == 1)
      fib.at(1) = 1;
    else
      fib.at(i) = (fib.at(i - 1) + fib.at(i - 2)) % 1000000007;
  }

  for (ll i = 0; i < M + 1; i++)
    ans = (ans * fib.at(ret.at(i))) % 1000000007;
  cout << ans << 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<int> a(n, 0);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    a.at(k) = 1;
  }
  const long long mod = 1000000007;

  vector<long long> dp(n);
  dp.at(0) = 1;
  if (!a.at(1))
    dp.at(1) = 1;
  for (int i = 2; i < n; i++) {
    if (a.at(i)) {
      dp.at(i) = 0;
      continue;
    }
    dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % mod;
  }

  long long ans = (dp.at(n - 1) + dp.at(n - 2)) % mod;
  cout << ans << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    a.at(k) = 1;
  }
  const long long mod = 1000000007;

  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<long long> dp(n);
  dp.at(0) = 1;
  if (!a.at(1))
    dp.at(1) = 1;
  for (int i = 2; i < n; i++) {
    if (a.at(i)) {
      dp.at(i) = 0;
      continue;
    }
    dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % mod;
  }

  long long ans = (dp.at(n - 1) + dp.at(n - 2)) % mod;
  cout << ans << endl;
}
Problem p03013 (C++)

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

using namespace std;

int main(void) {
  int N, M, now = 0, hole, maxi;
  long long result = 1;
  bool canDo = true;
  vector<int> step;
  vector<long long> fib;

  scanf("%d %d", &N, &M);

  // 連続した階段の数を配列にぶち込む
  for (int i = 0; i < M; i++) {
    scanf("%d", &hole);
    if (hole == now)
      canDo = false;
    step.push_back(hole - now - 1);
    now = hole + 1;
  }
  step.push_back(N - now);

  if (!canDo) {
    cout << 0 << endl;
    return 0;
  }

  // stepをソート  O(N log N)
  sort(step.begin(), step.end());

  maxi = step.back();

  // フィボナッチ数列の計算
  fib.push_back(1);
  fib.push_back(1);
  for (int i = 2; i <= maxi; i++)
    fib[i] = (fib[i - 1] + fib[i - 2]) % 1000000007;

  // 結果の計算
  for (const auto &e : step)
    result = result * fib[e] % 1000000007;

  cout << result << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  int N, M, now = 0, hole, maxi;
  long long result = 1;
  bool canDo = true;
  vector<int> step;
  vector<long long> fib;

  scanf("%d %d", &N, &M);

  // 連続した階段の数を配列にぶち込む
  for (int i = 0; i < M; i++) {
    scanf("%d", &hole);
    if (hole == now)
      canDo = false;
    step.push_back(hole - now - 1);
    now = hole + 1;
  }
  step.push_back(N - now);

  if (!canDo) {
    cout << 0 << endl;
    return 0;
  }

  // stepをソート  O(N log N)
  sort(step.begin(), step.end());

  maxi = step.back();

  // フィボナッチ数列の計算
  fib.push_back(1);
  fib.push_back(1);
  for (int i = 2; i <= maxi; i++)
    fib.push_back((fib[i - 1] + fib[i - 2]) % 1000000007);

  // 結果の計算
  for (const auto &e : step)
    result = result * fib[e] % 1000000007;

  cout << result << endl;
  return 0;
}
Problem p03013 (C++)

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

#define ll long long int

int main() {

  ll N, M;
  cin >> N >> M;

  ll tmp;
  vector<ll> a;
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }

  vector<ll> S(100010);
  S[0] = 1;

  int j = 0;
  if (a[0] == 1) {
    S[1] = 0;
    j++;
  } else {
    S[1] = 1;
  }

  for (int i = 2; i <= N; i++) {
    if (j < M && i == a[j]) {
      S[i] = 0;
      while (j < M && i == a[j]) {
        j++;
      }
    } else {
      S[i] = S[i - 1] + S[i - 2];
      S[i] %= 1000000007;
    }
  }

  cout << S[N] << endl;

  return 0;
}


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

#define ll long long int

int main() {

  ll N, M;
  cin >> N >> M;

  ll tmp;
  vector<ll> a;
  for (int i = 0; i < M; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }

  vector<ll> S(100010);
  S[0] = 1;

  int j = 0;
  if (M > 0 && a[0] == 1) {
    S[1] = 0;
    j++;
  } else {
    S[1] = 1;
  }

  for (int i = 2; i <= N; i++) {
    if (j < M && i == a[j]) {
      S[i] = 0;
      while (j < M && i == a[j]) {
        j++;
      }
    } else {
      S[i] = S[i - 1] + S[i - 2];
      S[i] %= 1000000007;
    }
  }

  cout << S[N] << endl;

  return 0;
}
Problem p03013 (C++)

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

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

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

  vector<ll> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    int MIN = min(n, i + 2);
    for (int j = i + 1; j <= MIN; j++) {
      if (stairs[j]) {
        dp[j] += dp[i];
        dp[j] %= mod;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}

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

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

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

  vector<ll> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    int MIN = min(n, i + 2);
    for (int j = i + 1; j <= MIN; j++) {
      if (stairs[j]) {
        dp[j] += dp[i];
        dp[j] %= mod;
      }
    }
  }

  cout << dp[n] << endl;

  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int k = M;
  long long int broken[10002], dp[10002] = {0};
  for (int i = 0; i < M; i++)
    cin >> broken[i];
  dp[N] = 1;
  for (int i = N - 1; 0 <= i; i--) {
    if (0 <= k - 1 && broken[k - 1] == i) {
      dp[i] = 0;
      k--;
    } else {
      dp[i] = (dp[i + 1] + dp[i + 2]) % 1000000007;
    }
  }
  cout << dp[0] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int k = M;
  long long int broken[100002], dp[100002] = {0};
  for (int i = 0; i < M; i++)
    cin >> broken[i];
  dp[N] = 1;
  for (int i = N - 1; 0 <= i; i--) {
    if (0 <= k - 1 && broken[k - 1] == i) {
      dp[i] = 0;
      k--;
    } else {
      dp[i] = (dp[i + 1] + dp[i + 2]) % 1000000007;
    }
  }
  cout << dp[0] << endl;
}
Problem p03013 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }

  auto itr = find(a.begin(), a.end(), 1);
  if (itr == a.end()) {
    dp.at(1) = 1;
  }

  itr = find(a.begin(), a.end(), 2);
  if (itr != a.end()) {
    dp.at(2) = 0;
  } else {
    dp.at(2) = dp.at(1) + 1;
  }

  for (int i = 3; i < n + 1; i++) {
    itr = find(a.begin(), a.end(), i);
    if (itr == a.end()) {
      dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % nmax;
    } else {
      dp.at(i) = 0;
    }
  }

  cout << dp.at(n) << endl;
  return (0);
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }

  auto itr = find(a.begin(), a.end(), 1);
  if (itr == a.end()) {
    dp.at(1) = 1;
  }

  itr = find(a.begin(), a.end(), 2);
  if (n > 1) {
    if (itr != a.end()) {
      dp.at(2) = 0;
    } else {
      dp.at(2) = dp.at(1) + 1;
    }
  }

  for (int i = 3; i < n + 1; i++) {
    itr = find(a.begin(), a.end(), i);
    if (itr == a.end()) {
      dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % nmax;
    } else {
      dp.at(i) = 0;
    }
  }

  cout << dp.at(n) << endl;
  return (0);
}
Problem p03013 (C++)

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

ll mod = 1000000007;

ll f(ll x, vector<ll> &dp) {
  if (x == 1) {
    dp.at(x) = 1;
    return dp.at(x);
  } else if (x == 2) {
    dp.at(x) = 2;
    return dp.at(x);
  }
  if (dp.at(x) != 0) {
    return dp.at(x);
  } else {
    dp.at(x) = (f(x - 2, dp) % mod + f(x - 1, dp) % mod) % mod;
    return dp.at(x);
  }
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);
  vector<ll> a(m);
  cin >> a.at(0);
  for (ll i = 1; i < m; i++) {
    cin >> a.at(i);
    if (a.at(i) - a.at(i - 1) == 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  vector<ll> s(m + 1, 0);
  if (m == 1) {
    s.at(0) = a.at(0) - 1;
    s.at(1) = n - a.at(0) - 1;
  } else {
    for (ll i = 0; i < m; i++) {
      if (i == 0) {
        s.at(i) = a.at(i) - 1;
      } else {
        s.at(i) = a.at(i) - a.at(i - 1) - 2;
      }
    }
    s.at(m) = n - a.at(m - 1) - 1;
  }
  ll ans = 1;
  for (ll i = 0; i < m + 1; i++) {
    if (s.at(i) == 0)
      continue;
    ans *= f(s.at(i), dp);
    ans %= mod;
  }
  cout << ans << endl;
}

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

ll mod = 1000000007;

ll f(ll x, vector<ll> &dp) {
  if (x == 1) {
    dp.at(x) = 1;
    return dp.at(x);
  } else if (x == 2) {
    dp.at(x) = 2;
    return dp.at(x);
  }
  if (dp.at(x) != 0) {
    return dp.at(x);
  } else {
    dp.at(x) = (f(x - 2, dp) % mod + f(x - 1, dp) % mod) % mod;
    return dp.at(x);
  }
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> dp(n + 1, 0);
  if (m == 0) {
    cout << f(n, dp) << endl;
    return 0;
  }
  vector<ll> a(m);
  cin >> a.at(0);
  for (ll i = 1; i < m; i++) {
    cin >> a.at(i);
    if (a.at(i) - a.at(i - 1) == 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  vector<ll> s(m + 1, 0);
  if (m == 1) {
    s.at(0) = a.at(0) - 1;
    s.at(1) = n - a.at(0) - 1;
  } else {
    for (ll i = 0; i < m; i++) {
      if (i == 0) {
        s.at(i) = a.at(i) - 1;
      } else {
        s.at(i) = a.at(i) - a.at(i - 1) - 2;
      }
    }
    s.at(m) = n - a.at(m - 1) - 1;
  }
  ll ans = 1;
  for (ll i = 0; i < m + 1; i++) {
    if (s.at(i) == 0)
      continue;
    ans *= f(s.at(i), dp);
    ans %= mod;
  }
  cout << ans << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
#define INF 1e9
typedef long long LL;
const LL mod = 1e9 + 7;

int main() {
  LL N, M;
  cin >> N >> M;
  vector<LL> a(N + 1);
  rep(i, M) {
    int num;
    cin >> num;
    a[num] = 1;
  }

  vector<LL> dp(N);
  dp[0] = 1;
  if (a[1] == 0)
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (a[i] == 0) {
      dp[i] = dp[i - 2] + dp[i - 1];
      dp[i] %= mod;
    }
  }

  int answer = dp[N];
  cout << answer << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
#define INF 1e9
typedef long long LL;
const LL mod = 1e9 + 7;

int main() {
  LL N, M;
  cin >> N >> M;
  vector<LL> a(N + 1);
  rep(i, M) {
    int num;
    cin >> num;
    a[num] = 1;
  }

  vector<LL> dp(N + 1);
  dp[0] = 1;
  if (a[1] == 0)
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (a[i] == 0) {
      dp[i] = dp[i - 2] + dp[i - 1];
      dp[i] %= mod;
    }
  }

  int answer = dp[N];
  cout << answer << endl;

  return 0;
}
Problem p03013 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> A(m);
  bitset<10020> safe;
  safe.set();
  if (m > 0) {
    rep(i, m) {
      int A;
      cin >> A;
      safe.set(A, 0);
    }
  }
  vector<ll> dp(n + 10);
  dp[1] = (safe.test(1)) ? 1 : 0;
  dp[2] = (safe.test(2)) ? dp[1] + 1 : 0;
  for (int i = 1; i <= n; i++) {
    (safe.test(i + 2)) ? dp[i + 2] = (dp[i + 1] + dp[i]) % MOD : dp[i + 2] = 0;
  }
  cout << dp[n] << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> A(m);
  bitset<100020> safe;
  safe.set();
  if (m > 0) {
    rep(i, m) {
      int A;
      cin >> A;
      safe.set(A, 0);
    }
  }
  vector<ll> dp(n + 10);
  dp[1] = (safe.test(1)) ? 1 : 0;
  dp[2] = (safe.test(2)) ? dp[1] + 1 : 0;
  for (int i = 1; i <= n; i++) {
    (safe.test(i + 2)) ? dp[i + 2] = (dp[i + 1] + dp[i]) % MOD : dp[i + 2] = 0;
  }
  cout << dp[n] << endl;
}
Problem p03013 (C++)

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

ll N, M;
set<ll> A;
ll memo[10000];
bool vis[10000];
ll mod = 1000000007;

ll go(ll pos) {
  if (pos > N) {
    return 0;
  }
  if (A.count(pos)) {
    return 0;
  }
  if (pos == N) {
    return 1;
  }
  if (vis[pos]) {
    return memo[pos];
  }
  ll res = 0;
  // salto 1
  res += go(pos + 1) % mod;
  // salto 2
  res += go(pos + 2) % mod;
  res %= mod;
  memo[pos] = res;
  vis[pos] = 1;
  return res;
}

int main() {
  cin >> N >> M;
  ll k;
  for (int i = 0; i < M; i++) {
    cin >> k;
    A.insert(k);
  }
  cout << go(0);
  return 0;
}


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

ll N, M;
set<ll> A;
ll memo[200000];
bool vis[200000];
ll mod = 1000000007;

ll go(ll pos) {
  if (pos > N) {
    return 0;
  }
  if (A.count(pos)) {
    return 0;
  }
  if (pos == N) {
    return 1;
  }
  if (vis[pos]) {
    return memo[pos];
  }
  ll res = 0;
  // salto 1
  res += go(pos + 1) % mod;
  // salto 2
  res += go(pos + 2) % mod;
  res %= mod;
  memo[pos] = res;
  vis[pos] = 1;
  return res;
}

int main() {
  cin >> N >> M;
  ll k;
  for (int i = 0; i < M; i++) {
    cin >> k;
    A.insert(k);
  }
  cout << go(0);
  return 0;
}
Problem p03013 (C++)

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

typedef long long ll;
typedef pair<int, int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a, b); }       // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数

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;
}

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

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

  vector<int> dp(N + 1, 0);
  dp[0] = 1;
  if (h.at(1))
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (h.at(i - 1))
      dp[i] += dp[i - 1];
    if (h.at(i - 2))
      dp[i] += dp[i - 2];
    dp[i] %= MOD;
  }

  cout << dp[N] << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a, b); }       // 最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // 最大公倍数

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;
}

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

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

  vector<int> dp(N + 1, 0);
  dp[0] = 1;
  if (h.at(1))
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (h.at(i - 1))
      dp[i] += dp[i - 1];
    if (h.at(i - 2))
      dp[i] += 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 <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

int main() {
  int N, M;
  long long mod = 1000000007;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> a(M);
  std::vector<long long> fibonatti(100000 + 5);
  for (int i = 0; i < M; i++) {
    scanf("%d", &a[i]);
  }
  fibonatti[0] = 1;
  fibonatti[1] = 1;
  fibonatti[2] = 2;
  for (int i = 3; i <= N; i++) {
    fibonatti[i] = fibonatti[i - 1] + fibonatti[i - 2];
    fibonatti[i] %= mod;
  }
  if (M == 0) {
    printf("%lld\n", fibonatti[N]);
  }

  long long ans = 1;
  ans *= fibonatti[a[0] - 1];
  ans %= mod;
  // printf("ans1=%lld\n",ans);
  for (int i = 1; i < M; i++) {
    if (a[i] - a[i - 1] == 1) {
      // printf("ooops\n");
      printf("0\n");
      return 0;
    }
    // printf("*=%lld\n",fibonatti[a[i]-a[i-1]-2]);
    ans *= fibonatti[a[i] - a[i - 1] - 2];
    ans %= mod;
    // printf("ans=%lld\n",ans);
  }
  ans *= fibonatti[N - a[M - 1] - 1];
  ans %= mod;
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

int main() {
  int N, M;
  long long mod = 1000000007;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int> a(M);
  std::vector<long long> fibonatti(100000 + 5);
  for (int i = 0; i < M; i++) {
    scanf("%d", &a[i]);
  }
  fibonatti[0] = 1;
  fibonatti[1] = 1;
  fibonatti[2] = 2;
  for (int i = 3; i <= N; i++) {
    fibonatti[i] = fibonatti[i - 1] + fibonatti[i - 2];
    fibonatti[i] %= mod;
  }
  if (M == 0) {
    printf("%lld\n", fibonatti[N]);
    return 0;
  }

  long long ans = 1;
  ans *= fibonatti[a[0] - 1];
  ans %= mod;
  // printf("ans1=%lld\n",ans);
  for (int i = 1; i < M; i++) {
    if (a[i] - a[i - 1] == 1) {
      // printf("ooops\n");
      printf("0\n");
      return 0;
    }
    // printf("*=%lld\n",fibonatti[a[i]-a[i-1]-2]);
    ans *= fibonatti[a[i] - a[i - 1] - 2];
    ans %= mod;
    // printf("ans=%lld\n",ans);
  }
  ans *= fibonatti[N - a[M - 1] - 1];
  ans %= mod;
  printf("%lld\n", ans);
  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<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }
  vector<int> b(n + 2);
  b.at(1) = 1;
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (i == a.at(j)) {
      j = min(j + 1, m - 1);
    } else {
      b.at(i + 1) = (b.at(i) + b.at(i - 1)) % 1000000007;
    }
  }
  cout << b.at(n + 1) << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
  }
  vector<int> b(n + 2);
  b.at(1) = 1;
  if (m == 0) {
    for (int i = 1; i <= n; i++) {
      b.at(i + 1) = (b.at(i) + b.at(i - 1)) % 1000000007;
    }
    cout << b.at(n + 1) << endl;
    return 0;
  }
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (i == a.at(j)) {
      j = min(j + 1, m - 1);
    } else {
      b.at(i + 1) = (b.at(i) + b.at(i - 1)) % 1000000007;
    }
  }
  cout << b.at(n + 1) << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e3 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double eps = 1e-10;
ll n, m, a[MAXN], dp[MAXN], broken[MAXN];
ll add(ll x, ll y) {
  ll ret = x + y;
  if (ret >= MOD) {
    return ret - MOD;
  }
  return ret;
}
void solve() {
  dp[0] = 1;
  for (ll i = 1; i <= n; i++) {
    if (!broken[i]) {
      if (i == 1) {
        dp[i] = dp[i - 1];
      } else {
        dp[i] = add(dp[i - 1], dp[i - 2]);
      }
    }
  }
  printf("%lld\n", dp[n]);
}
int main() {
  //    freopen("c://duipai//data.txt","r",stdin);
  //    freopen("c://duipai//wa.txt","w",stdout);
  while (~scanf("%lld %lld", &n, &m)) {
    //        string ss;
    //        cin>>ss;
    //        cout<<ss<<endl;
    for (ll i = 1; i <= m; i++) {
      scanf("%lld", &a[i]);
      broken[a[i]] = 1;
    }
    solve();
  }
}
/*

*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double eps = 1e-10;
ll n, m, a[MAXN], dp[MAXN], broken[MAXN];
ll add(ll x, ll y) {
  ll ret = x + y;
  if (ret >= MOD) {
    return ret - MOD;
  }
  return ret;
}
void solve() {
  dp[0] = 1;
  for (ll i = 1; i <= n; i++) {
    if (!broken[i]) {
      if (i == 1) {
        dp[i] = dp[i - 1];
      } else {
        dp[i] = add(dp[i - 1], dp[i - 2]);
      }
    }
  }
  printf("%lld\n", dp[n]);
}
int main() {
  //    freopen("c://duipai//data.txt","r",stdin);
  //    freopen("c://duipai//wa.txt","w",stdout);
  while (~scanf("%lld %lld", &n, &m)) {
    //        string ss;
    //        cin>>ss;
    //        cout<<ss<<endl;
    for (ll i = 1; i <= m; i++) {
      scanf("%lld", &a[i]);
      broken[a[i]] = 1;
    }
    solve();
  }
}
/*

*/
Problem p03013 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

constexpr long long mod = 1e9 + 7;

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

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

  int idx = 0;

  vector<long long> ways(N, 0LL);
  if (find(a.begin(), a.end(), 0) == a.end())
    ways[0] = 1;
  else
    idx = distance(a.begin(), find(a.begin(), a.end(), 0));
  if (find(a.begin() + idx, a.end(), 1) == a.end())
    ways[1] = 1;
  else
    idx = distance(a.begin(), find(a.begin(), a.end(), 1));

  for (int i = 1; i < N; i++) {
    if (find(a.begin() + idx, a.end(), i) != a.end()) {
      idx = idx = distance(a.begin(), find(a.begin(), a.end(), i));
      ways[i] = 0;
      continue;
    }

    if (i >= 1)
      ways[i] += ways[i - 1];
    if (i >= 2)
      ways[i] += ways[i - 2];

    ways[i] %= mod;
  }

  cout << ways[N - 1] << endl;
  return 0;
}

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

constexpr long long mod = 1e9 + 7;

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

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

  int idx = 0;

  vector<long long> ways(N, 0LL);
  if (find(a.begin(), a.end(), 0) == a.end())
    ways[0] = 1;
  else
    idx = distance(a.begin(), find(a.begin(), a.end(), 0));
  if (find(a.begin() + idx, a.end(), 1) == a.end())
    ways[1] = 1;
  else
    idx = distance(a.begin(), find(a.begin(), a.end(), 1));

  for (int i = 1; i < N; i++) {
    if (find(a.begin() + idx, a.end(), i) != a.end()) {
      idx = distance(a.begin(), find(a.begin() + idx, a.end(), i));
      ways[i] = 0;
      continue;
    }

    if (i >= 1)
      ways[i] += ways[i - 1];
    if (i >= 2)
      ways[i] += ways[i - 2];

    ways[i] %= mod;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// value
int N, M;
vi a;

vl dp;

void solve() {

  cin >> N >> M;
  a.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  dp.resize(N + 1);

  dp[0] = 1;
  int cur = 0;
  if (a[0] != 1)
    dp[1] = 1;
  else {
    dp[1] = 0;
    cur++;
  }
  for (ll i = 2; i <= N; i++) {
    if (cur < M && i == a[cur]) {
      dp[i] = 0;
      cur++;
      continue;
    }
    dp[i] = dp[i - 1] + dp[i - 2];
    dp[i] %= MOD;
  }

  cout << dp[N] % MOD << endl;

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// value
int N, M;
vi a;

vl dp;

void solve() {

  cin >> N >> M;
  a.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  dp.resize(N + 1);

  dp[0] = 1;
  int cur = 0;
  dp[1] = 1;
  if (a.size() != 0) {
    if (a[0] != 1)
      dp[1] = 1;
    else {
      dp[1] = 0;
      cur++;
    }
  }
  for (ll i = 2; i <= N; i++) {
    if (cur < M && i == a[cur]) {
      dp[i] = 0;
      cur++;
      continue;
    }
    dp[i] = dp[i - 1] + dp[i - 2];
    dp[i] %= MOD;
  }

  cout << dp[N] % MOD << endl;

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;
ll dp[111111];

int main() {
  cin >> N >> M;
  vector<int> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  M = 0;
  dp[0] = 1;
  if (a[0] == 1)
    M++;
  else
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (a[M] == i)
      M++;
    else
      dp[i] = dp[i - 1] + dp[i - 2];
    dp[i] %= mod;
  }
  cout << dp[N] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;
ll dp[111111];

int main() {
  cin >> N >> M;
  vector<int> a(M + 1);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }
  M = 0;
  dp[0] = 1;
  if (a[0] == 1)
    M++;
  else
    dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (a[M] == i)
      M++;
    else
      dp[i] = dp[i - 1] + dp[i - 2];
    dp[i] %= mod;
  }
  cout << dp[N] << endl;
}
Problem p03013 (C++)

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

int main() {
  int64_t dp[100000];
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  for (int i = 1; i < 100000; i++) {
    dp[i + 2] = dp[i] % 1000000007 + dp[i + 1] % 1000000007;
  }
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> sd(M);
  int c = 1;

  for (int i = 0; i < M; i++)

  {
    int a;
    cin >> a;
    sd.at(i) = a;
    if (i > 0 && sd.at(i) - sd.at(i - 1) == 1) {
      c = 0;
    }
  }
  if (c == 0)
    cout << 0;
  else {
    int64_t g = 1;
    for (int i = 0; i < M + 1; i++) {
      if (i == M)
        g = g * dp[N - sd.at(M - 1) - 1] % 1000000007;

      if (i == M - 1)
        g = g * dp[sd.at(0) - 1];
      else if (i < M - 1)
        g = g * dp[sd.at(i + 1) - sd.at(i) - 2] % 1000000007;
    }
    cout << g << endl;
  }
}


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

int main() {
  int64_t dp[100000];
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  for (int i = 1; i < 100000; i++) {
    dp[i + 2] = dp[i] % 1000000007 + dp[i + 1] % 1000000007;
  }
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> sd(M);
  int c = 1;

  for (int i = 0; i < M; i++)

  {
    int a;
    cin >> a;
    sd.at(i) = a;
    if (i > 0 && sd.at(i) - sd.at(i - 1) == 1) {
      c = 0;
    }
  }
  if (c == 0)
    cout << 0;
  else if (M == 0)
    cout << dp[N];
  else {
    int64_t g = 1;
    for (int i = 0; i < M + 1; i++) {
      if (i == M)
        g = g * dp[N - sd.at(M - 1) - 1] % 1000000007;

      if (i == M - 1)
        g = g * dp[sd.at(0) - 1];
      else if (i < M - 1)
        g = g * dp[sd.at(i + 1) - sd.at(i) - 2] % 1000000007;
    }
    cout << g << endl;
  }
}
Problem p03013 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

#define mst(a, b) memset(a, b, sizeof(a))
#define repi(a, b) for (ll i = a; i < b; i++)
#define repj(a, b) for (ll j = a; j < b; j++)
#define pii pair<int, int>

#ifdef LOCAL
#define fre() freopen("in.txt", "r", stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

// static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
// }();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
// #define scanf abcabc
// #define printf abcabc
#endif
// #ifndef FASTIO
// #define cin abcabc
// #define cout abcabc
// #endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;

const int mod = 1000000007;
int a[100010], vis[100010];
int rifa(int x) {
  if (a[x])
    return 0;
  if (vis[x])
    return vis[x];
  if (x == 1)
    return 1;
  else if (x == 2)
    return rifa(x - 1) + 1;
  int tmp = (rifa(x - 1) + rifa(x - 2)) % mod;
  vis[x] = tmp;
  return tmp;
}
int main() {
  fre();
  IOS;
  int n, m;
  cin >> n >> m;
  repi(0, m) {
    int tmp;
    cin >> tmp;
    a[tmp] = 1;
  }
  cout << rifa(n) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

#define mst(a, b) memset(a, b, sizeof(a))
#define repi(a, b) for (ll i = a; i < b; i++)
#define repj(a, b) for (ll j = a; j < b; j++)
#define pii pair<int, int>

#ifdef LOCAL
#define fre() freopen("in.txt", "r", stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

// static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
// }();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
// #define scanf abcabc
// #define printf abcabc
#endif
// #ifndef FASTIO
// #define cin abcabc
// #define cout abcabc
// #endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;

const int mod = 1000000007;
int a[100010], vis[100010];
int rifa(int x) {
  if (a[x])
    return 0;
  if (vis[x])
    return vis[x];
  if (x == 1)
    return 1;
  else if (x == 2)
    return rifa(x - 1) + 1;
  int tmp = (rifa(x - 1) + rifa(x - 2)) % mod;
  vis[x] = tmp;
  return tmp;
}
int main() {
  fre();
  IOS;
  int n, m;
  cin >> n >> m;
  repi(0, m) {
    int tmp;
    cin >> tmp;
    a[tmp] = 1;
    if (a[tmp - 1] || a[tmp + 1]) {
      cout << "0\n";
      return 0;
    }
  }
  cout << rifa(n) << endl;
  return 0;
}
Problem p03013 (C++)

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

typedef long long ll;
using namespace std;
#define mod 1000000007

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  for (ll i = 0; i < m; i++) {
    cin >> a[i];
  }
  vector<ll> f(n + 1);
  f[0] = 1;
  f[1] = 1;
  ll next = 0;
  if (a[0] == 1) {
    f[1] = 0;
    if (next < m - 1)
      next++;
  }
  for (ll i = 2; i <= n; i++) {
    f[i] = f[i - 1] + f[i - 2];
    if (a[next] == i && next <= m - 1) {
      f[i] = 0;
      if (next < m - 1)
        next++;
    }
    f[i] %= mod;
  }
  cout << f[n] << endl;
  return 0;
}


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

typedef long long ll;
using namespace std;
#define mod 1000000007

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m + 3);
  for (ll i = 0; i < m; i++) {
    cin >> a[i];
  }
  vector<ll> f(n + 1);
  f[0] = 1;
  f[1] = 1;
  ll next = 0;
  if (a[0] == 1) {
    f[1] = 0;
    if (next < m - 1)
      next++;
  }
  for (ll i = 2; i <= n; i++) {
    f[i] = f[i - 1] + f[i - 2];
    if (a[next] == i && next <= m - 1) {
      f[i] = 0;
      if (next < m - 1)
        next++;
    }
    f[i] %= mod;
  }
  cout << f[n] << endl;
  return 0;
}
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""


Fixed submission:
n, m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
dp = [0] * (n + 1)
for i in range(n + 1):
    if i in A:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

"""
100 5
1
23
45
67
89
"""
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;
typedef long long ll;

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

  vector<int> broken(n);
  rep(i, n) {
    int a;
    cin >> a;
    broken[a] = 1;
  }

  vector<int> dp(n + 2);
  const int mod = 1000000007;
  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;
typedef long long ll;

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

  vector<int> broken(n);
  rep(i, m) {
    int a;
    cin >> a;
    broken[a] = 1;
  }

  vector<int> dp(n + 2);
  const int mod = 1000000007;
  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 (Python)

Buggy submission (status: Runtime Error):
def solve():
    N, M = map(int, input().split())
    A = []
    if M != 0:
        A = [int(input()) for _ in range(M)]
    A.sort(reverse=True)
    mm = 10**9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1  # 0段目に行くパターンは1とする
    tag = -1
    if len(A) != 0:
        tag = A.pop()
    # 1段目のパターンを設定
    if tag == 1:
        dp[1] = 0
        tag = A.pop()
    else:
        dp[1] = 1
    for i in range(2, N + 1):
        if i == tag:
            if len(A) == 0:
                tag = -1
            else:
                tag = A.pop()
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mm
    print(dp[N])


if __name__ == "__main__":
    solve()


Fixed submission:
def solve():
    N, M = map(int, input().split())
    A = []
    if M != 0:
        A = [int(input()) for _ in range(M)]
    A.sort(reverse=True)
    mm = 10**9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1  # 0段目に行くパターンは1とする
    tag = -1
    if len(A) != 0:
        tag = A.pop()
    # 1段目のパターンを設定
    if tag == 1:
        dp[1] = 0
        if len(A) == 0:
            tag = -1
        else:
            tag = A.pop()
    else:
        dp[1] = 1
    for i in range(2, N + 1):
        if i == tag:
            if len(A) == 0:
                tag = -1
            else:
                tag = A.pop()
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mm
    print(dp[N])


if __name__ == "__main__":
    solve()
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
n, m = list(map(int, input().split(" ")))

broken = [False] * (n + 1)
for i in range(m):
    broken[int(input())] = True

mod = 1_000_000_007

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 0 if broken[1] else 1

for i in range(2, n + 1):
    if broken[i]:
        dp[i] = 0
    else:
        c = dp[i - 1] + dp[i - 2]
        if c > mod:
            c = c % mod
        dp[i] = c

print(dp[n])


Fixed submission:
n, m = list(map(int, input().split(" ")))

broken = [False] * (n + 1)
for i in range(m):
    broken[int(input())] = True

mod = 1000000007

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 0 if broken[1] else 1

for i in range(2, n + 1):
    if broken[i]:
        dp[i] = 0
    else:
        c = dp[i - 1] + dp[i - 2]
        if c > mod:
            c = c % mod
        dp[i] = c

print(dp[n])
Problem p03013 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())

a = [int(input()) for i in range(m)]

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])


Fixed submission:
n, m = map(int, input().split())

a = set()
for i in range(m):
    a_tmp = int(input())
    a.add(a_tmp)

# a = [int(input()) for i in range(m)]

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])
Problem p03014 (C++)

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

const int MAX = 1e3 + 10;

typedef long long ll;

int main() {
  int left[MAX][MAX], right[MAX][MAX], up[MAX][MAX], down[MAX][MAX];
  char a[MAX][MAX];

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

  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      cin >> a[i][j];

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == '#')
        left[i][j] = 0;
      else
        left[i][j] = 1 + left[i][j - 1];
    }
  }

  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= m; i++) {
      if (a[i][j] == '#')
        up[i][j] = 0;
      else
        up[i][j] = 1 + up[i - 1][j];
    }
  }

  for (int i = 1; i <= m; i++) {
    for (int j = n; j > 0; j--) {
      if (a[i][j] == '#')
        right[i][j] = 0;
      else
        right[i][j] = 1 + right[i][j + 1];
    }
  }

  for (int j = 1; j <= n; j++) {
    for (int i = m; i > 0; i--) {
      if (a[i][j] == '#')
        down[i][j] = 0;
      else
        down[i][j] = 1 + down[i + 1][j];
    }
  }

  int ans = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      int t = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3;
      ans = max(ans, t);
    }
  }

  cout << ans;
}

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

const int MAX = 2e3 + 10;

typedef long long ll;

int main() {
  int left[MAX][MAX], right[MAX][MAX], up[MAX][MAX], down[MAX][MAX];
  char a[MAX][MAX];

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

  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      cin >> a[i][j];

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == '#')
        left[i][j] = 0;
      else
        left[i][j] = 1 + left[i][j - 1];
    }
  }

  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= m; i++) {
      if (a[i][j] == '#')
        up[i][j] = 0;
      else
        up[i][j] = 1 + up[i - 1][j];
    }
  }

  for (int i = 1; i <= m; i++) {
    for (int j = n; j > 0; j--) {
      if (a[i][j] == '#')
        right[i][j] = 0;
      else
        right[i][j] = 1 + right[i][j + 1];
    }
  }

  for (int j = 1; j <= n; j++) {
    for (int i = m; i > 0; i--) {
      if (a[i][j] == '#')
        down[i][j] = 0;
      else
        down[i][j] = 1 + down[i + 1][j];
    }
  }

  int ans = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      int t = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3;
      ans = max(ans, t);
    }
  }

  cout << ans;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define mod 1000000007
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back

using namespace std;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;
  char grid[201][201];
  int ans[201][201] = {};

  vector<queue<int>> q(2001);
  vector<queue<int>> r(2001);

  rep(i, 0, H) rep(j, 0, W) {
    cin >> grid[i][j];
    if (grid[i][j] == '#') {
      q[i].push(j);
      r[j].push(i);
    }
  }
  int m, u;

  rep(i, 0, H) { q[i].push(W); }
  rep(i, 0, W) { r[i].push(H); }

  rep(i, 0, H) {
    m = -1;
    u = q[i].front();
    q[i].pop();
    rep(j, 0, W) {
      if (u > j) {
        ans[i][j] += (u - m - 1);
      } else if (u == j) {
        m = u;
        u = q[i].front();
        q[i].pop();
      }
    }
  }

  rep(j, 0, W) {
    m = -1;
    u = r[j].front();
    r[j].pop();
    rep(i, 0, H) {
      if (u > i) {
        ans[i][j] += (u - m - 1);
      } else if (u == i) {
        m = u;
        u = r[j].front();
        r[j].pop();
      }
    }
  }

  int maxa = 0;
  rep(i, 0, H) rep(j, 0, W) { maxa = max(maxa, ans[i][j]); }

  if (maxa != 0)
    cout << maxa - 1;
  else
    cout << 0;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define mod 1000000007
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back

using namespace std;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;
  char grid[2001][2001];
  int ans[2001][2001] = {};

  vector<queue<int>> q(2001);
  vector<queue<int>> r(2001);

  rep(i, 0, H) rep(j, 0, W) {
    cin >> grid[i][j];
    if (grid[i][j] == '#') {
      q[i].push(j);
      r[j].push(i);
    }
  }
  int m, u;

  rep(i, 0, H) { q[i].push(W); }
  rep(i, 0, W) { r[i].push(H); }

  rep(i, 0, H) {
    m = -1;
    u = q[i].front();
    q[i].pop();
    rep(j, 0, W) {
      if (u > j) {
        ans[i][j] += (u - m - 1);
      } else if (u == j) {
        m = u;
        u = q[i].front();
        q[i].pop();
      }
    }
  }

  rep(j, 0, W) {
    m = -1;
    u = r[j].front();
    r[j].pop();
    rep(i, 0, H) {
      if (u > i) {
        ans[i][j] += (u - m - 1);
      } else if (u == i) {
        m = u;
        u = r[j].front();
        r[j].pop();
      }
    }
  }

  int maxa = 0;
  rep(i, 0, H) rep(j, 0, W) { maxa = max(maxa, ans[i][j]); }

  if (maxa != 0)
    cout << maxa - 1;
  else
    cout << 0;

  return 0;
}
Problem p03014 (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 h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(h);
    rep(i, h) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + 1][j] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << 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 h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(h);
    rep(i, h) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      rep(k, l) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] - 1);
  cout << ans << endl;
  return 0;
}