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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = unsigned long long;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  vector<ll> b(n);
  REP(i, n + 1) b[i] = -1;
  REP(i, m) {
    cin >> a[i];
    b[a[i]] = 0;
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  } else if (n == 2) {
    if (b[1] == 0)
      cout << 1 << endl;
    else
      cout << 2 << endl;
    return 0;
  }
  b[0] = 1;
  if (b[1] != 0)
    b[1] = 1;

  FOR(i, 2, n + 1) {
    if (b[i] == 0)
      continue;
    b[i] = (b[i - 1] + b[i - 2]) % MOD;
    // printf("b[%d] = %lld + %lld\n",i,b[i-1],b[i-2]);
  }

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = unsigned long long;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  vector<ll> b(n + 1);
  REP(i, n + 1) b[i] = -1;
  REP(i, m) {
    cin >> a[i];
    b[a[i]] = 0;
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  } else if (n == 2) {
    if (b[1] == 0)
      cout << 1 << endl;
    else
      cout << 2 << endl;
    return 0;
  }
  b[0] = 1;
  if (b[1] != 0)
    b[1] = 1;

  FOR(i, 2, n + 1) {
    if (b[i] == 0)
      continue;
    b[i] = (b[i - 1] + b[i - 2]) % MOD;
    // printf("b[%d] = %lld + %lld\n",i,b[i-1],b[i-2]);
  }

  cout << b[n] << endl;
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9 + 7;
int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> A(K);
  vector<long long> count(100001);
  count[0] = 1;
  count[1] = 1;
  for (int i = 2; i < 100001; i++) {
    count[i] = count[i - 1] + count[i - 2];
    count[i] %= INF;
  }
  for (int i = 0; i < K; i++) {
    cin >> A[i];
    if (i != 0)
      if (A[i] - 1 == A[i - 1]) {
        cout << 0 << endl;
        return 0;
      }
  }
  long long ans = 1;
  for (int i = 0; i <= K; i++) {
    if (i == 0)
      ans *= count[A[i] - 1];
    else if (i == K)
      ans *= count[N - A[i - 1] - 1];
    else
      ans *= count[A[i] - A[i - 1] - 2];
    ans %= INF;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9 + 7;
int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> A(K);
  vector<long long> count(100001);
  count[0] = 1;
  count[1] = 1;
  for (int i = 2; i < 100001; i++) {
    count[i] = count[i - 1] + count[i - 2];
    count[i] %= INF;
  }
  for (int i = 0; i < K; i++) {
    cin >> A[i];
    if (i != 0)
      if (A[i] - 1 == A[i - 1]) {
        cout << 0 << endl;
        return 0;
      }
  }
  if (K == 0) {
    cout << count[N] << endl;
    return 0;
  }
  long long ans = 1;
  for (int i = 0; i <= K; i++) {
    if (i == 0)
      ans *= count[A[i] - 1];
    else if (i == K)
      ans *= count[N - A[i - 1] - 1];
    else
      ans *= count[A[i] - A[i - 1] - 2];
    ans %= INF;
  }
  cout << ans << endl;
}
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(100000)

N, M = map(int, input().split())
A = []
ANS = []
for i in range(N + 10):
    ANS.append(None)

for _ in range(M):
    a = int(input())
    A.append(a)
    ANS[a] = 0


def f(x):
    # print(ANS)
    # if x in A:
    #     print('::::', x)
    #     d[x] = 0
    #     return 0
    if ANS[x] is not None:
        return ANS[x]

    if x > N:
        return 0
    if x == N:
        return 1

    # if d.get(x + 1):
    #     x1 = d.get(x + 1)
    # else:
    #     x1 = f(x + 1)
    #     d[x + 1] = x1
    #
    # if d.get(x + 2):
    #     x2 = d.get(x + 2)
    # else:
    #     x2 = f(x + 2)
    #     d[x + 2] = x2

    # ans = x1 + x2
    ans = f(x + 1) + f(x + 2)
    ANS[x] = ans
    return ans


print(f(0) % 1000000007)


Fixed submission:
import sys

sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
A = []
ANS = []
for i in range(N + 10):
    ANS.append(None)

for _ in range(M):
    a = int(input())
    A.append(a)
    ANS[a] = 0


def f(x):
    # print(ANS)
    # if x in A:
    #     print('::::', x)
    #     d[x] = 0
    #     return 0
    if ANS[x] is not None:
        return ANS[x]

    if x > N:
        return 0
    if x == N:
        return 1

    # if d.get(x + 1):
    #     x1 = d.get(x + 1)
    # else:
    #     x1 = f(x + 1)
    #     d[x + 1] = x1
    #
    # if d.get(x + 2):
    #     x2 = d.get(x + 2)
    # else:
    #     x2 = f(x + 2)
    #     d[x + 2] = x2

    # ans = x1 + x2
    ans = f(x + 1) + f(x + 2)
    ANS[x] = ans
    return ans


print(f(0) % 1000000007)
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
import sys

sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
A = []
ANS = []
for i in range(N + 10):
    ANS.append(None)

for _ in range(M):
    a = int(input())
    A.append(a)
    ANS[a] = 0


def f(x):
    if ANS[x] is not None:
        return ANS[x]

    if x > N:
        return 0
    if x == N:
        return 1

    if ANS[x + 1] is None:
        x1 = f(x + 1)
        ANS[x + 1] = x1
    else:
        x1 = ANS[x + 1]

    if ANS[x + 2] is None:
        x2 = f(x + 2)
        ANS[x + 2] = x1
    else:
        x2 = ANS[x + 2]

    ans = x1 + x2
    # ans = f(x + 1) + f(x + 2)
    ANS[x] = ans
    return ans


print(f(0) % 1000000007)


Fixed submission:
import sys

sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
A = []
ANS = []
for i in range(N + 10):
    ANS.append(None)

for _ in range(M):
    a = int(input())
    A.append(a)
    ANS[a] = 0


def f(x):
    if ANS[x] is not None:
        return ANS[x]

    if x > N:
        return 0
    if x == N:
        return 1

    if ANS[x + 1] is None:
        x1 = f(x + 1)
        ANS[x + 1] = x1
    else:
        x1 = ANS[x + 1]

    if ANS[x + 2] is None:
        x2 = f(x + 2)
        ANS[x + 2] = x1
    else:
        x2 = ANS[x + 2]

    ans = x1 + x2
    # ans = f(x + 1) + f(x + 2)
    ANS[x] = ans
    return ans


print(f(0) % 1000000007)
Problem p03013 (Python)

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

s = [0] * (n + 1)
s[-1] = 1
for _ in range(m):
    a = int(input())
    s[a] = None

if s[0] is None and s[1] is None:
    print(0)
    exit()

for i in range(n - 1, -1, -1):
    if s[i] is None:
        continue
    if i + 1 < len(s) and s[i + 1] is not None:
        s[i] += s[i + 1]
    if i + 2 < len(s) and s[i + 2] is not None:
        s[i] += s[i + 2]

print(s[0] % 1_000_000_007)


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

s = [0] * (n + 1)
s[-1] = 1
for _ in range(m):
    a = int(input())
    s[a] = None

if s[0] is None and s[1] is None:
    print(0)
    exit()

for i in range(n - 1, -1, -1):
    if s[i] is None:
        continue
    if i + 1 < len(s) and s[i + 1] is not None:
        s[i] += s[i + 1]
    if i + 2 < len(s) and s[i + 2] is not None:
        s[i] += s[i + 2]

print(s[0] % 1000000007)
Problem p03013 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]

    mod = 10**9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1

    for i in range(1, N + 1):
        if i in A:
            continue

        if i == 1:
            dp[1] = dp[0]
            continue

        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

    print(dp[N])


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    A = set([int(input()) for _ in range(M)])

    mod = 10**9 + 7
    dp = [0] * (N + 1)
    dp[0] = 1

    for i in range(1, N + 1):
        if i in A:
            continue

        if i == 1:
            dp[1] = dp[0]
            continue

        dp[i] = dp[i - 1] + dp[i - 2]
        dp[i] %= mod

    print(dp[N])


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

Buggy submission (status: Runtime Error):
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, read().split())
    a = {int(read()) - 1 for _ in range(m)}
    mod = 10**9 + 7
    dp = [0] * n
    if 0 not in a:
        dp[0] = 1
    if 1 not in a:
        dp[1] = 1 + dp[0]
    for i in range(2, n):
        if i in a:
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, read().split())
    a = {int(read()) - 1 for _ in range(m)}
    if n == 1:
        print(1)
        return
    mod = 10**9 + 7
    dp = [0] * n
    if 0 not in a:
        dp[0] = 1
    if 1 not in a:
        dp[1] = 1 + dp[0]
    for i in range(2, n):
        if i in a:
            continue
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
    print(dp[-1])


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

Buggy submission (status: Time Limit Exceeded):
# input
N, M = map(int, input().split())
a = []
a_append = a.append

for n in range(M):
    a_append(int(input()))

mod = 1000000007

# check
check = {}
for n in range(N + 1):
    if n in a:
        check[n] = False
    else:
        check[n] = True

dp = {0: 1}
if check[1] is True:
    dp[1] = 1
else:
    dp[1] = 0

for n in range(2, N + 1):
    dp[n] = 0
    if check[n - 1] is True:
        dp[n] += dp[n - 1]
    if check[n - 2] is True:
        dp[n] += dp[n - 2]
    dp[n] %= mod

print(dp[N])


Fixed submission:
# input
N, M = map(int, input().split())
a = []
a_append = a.append

for n in range(M):
    a_append(int(input()))

mod = 1000000007

# check
check = [True] * (N + 1)
for i in a:
    check[i] = False

dp = {0: 1}
if check[1] is True:
    dp[1] = 1
else:
    dp[1] = 0

for n in range(2, N + 1):
    dp[n] = 0
    if check[n - 1] is True:
        dp[n] += dp[n - 1]
    if check[n - 2] is True:
        dp[n] += dp[n - 2]
    dp[n] %= mod

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

Buggy submission (status: Time Limit Exceeded):
Q = 1000000007
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
dp = {0: 1, 1: 0 if 1 in a else 1}

for k in range(2, n + 1):
    dp[k] = (0 if k in a else dp[k - 1] + dp[k - 2]) % Q


print(dp[n])


Fixed submission:
Q = 1000000007
n, m = map(int, input().split())
a = set([int(input()) for _ in range(m)])
dp = {0: 1, 1: 0 if 1 in a else 1}

for k in range(2, n + 1):
    dp[k] = (0 if k in a else dp[k - 1] + dp[k - 2]) % Q


print(dp[n])
Problem p03013 (C++)

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

using namespace std;

int main() {
  int N, M;
  vector<int> A;
  int a;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a;
    A.push_back(a);
  }
  long long way[101000] = {0};
  way[0] = 1;
  int nextout = 0;
  for (int w = 1; w <= N; w++) {
    if (w == A[nextout]) {
      nextout++;
      continue;
    }
    if (w == 1)
      way[w] = way[w - 1];
    else
      way[w] = way[w - 1] + way[w - 2];
    way[w] %= 1000000007;
  }
  cout << way[N] << endl;

  return 0;
}


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

using namespace std;

int main() {
  int N, M;
  vector<int> A;
  int a;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a;
    A.push_back(a);
  }
  long long way[101000] = {0};
  way[0] = 1;
  int nextout = 0;
  for (int w = 1; w <= N; w++) {
    if (nextout < M && w == A[nextout]) {
      nextout++;
      continue;
    }
    if (w == 1)
      way[w] = way[w - 1];
    else
      way[w] = way[w - 1] + way[w - 2];
    way[w] %= 1000000007;
  }
  cout << way[N] << endl;

  return 0;
}
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    nums = []
    # nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            # nums[i] = 0
            continue

        if i == 0:
            nums.append(1)
            # nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
            # nums[i] = nums[i-1] + 1
        else:
            nums.append((nums[-1] % X + nums[-2] % X) % X)
            # nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    nums = []
    # nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            # nums[i] = 0
            continue

        if i == 0:
            nums.append(1)
            # nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
            # nums[i] = nums[i-1] + 1
        else:
            nums.append((nums[-1] % X + nums[-2] % X) % X)
            # nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))


Fixed submission:
n, m = map(int, input().split())
hole_ids = {int(input()) - 1: 0 for _ in range(m)}
X = 1000000007


def solve(n, hole_ids):
    nums = []
    # nums = [0] * n
    for i in range(n):
        if i in hole_ids:
            nums.append(0)
            # nums[i] = 0
            continue

        if i == 0:
            nums.append(1)
            # nums[i] = 1
        elif i == 1:
            # 1つ前から1段上がるから2つ前から2個飛ばし
            nums.append(nums[-1] + 1)
            # nums[i] = nums[i-1] + 1
        else:
            nums.append((nums[-1] % X + nums[-2] % X) % X)
            # nums[i] = (nums[i-1] + nums[i-2]) % X
    return nums[-1]


print(solve(n, hole_ids))
Problem p03013 (Python)

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

for i in range(m):
    a.append(int(input().strip()))

broken = [False] * (n + 1)

for i in range(m):
    broken[a[i]] = True

dp = []
dp.append(1)

if broken[1]:
    dp.append(0)
else:
    dp.append(1)

for i in range(2, n + 1, 1):
    if broken[i]:
        dp.append(0)
    else:
        dp.append((dp[i - 1] + dp[i - 2]) % 1_000_000_007)

print(dp[n])


Fixed submission:
n, m = list(map(int, input().split()))
a = []

for i in range(m):
    a.append(int(input().strip()))

broken = [False] * (n + 1)

for i in range(m):
    broken[a[i]] = True

dp = []
dp.append(1)

if broken[1]:
    dp.append(0)
else:
    dp.append(1)

for i in range(2, n + 1, 1):
    if broken[i]:
        dp.append(0)
    else:
        dp.append((dp[i - 1] + dp[i - 2]) % 1000000007)

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

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
steps = [True] * (N + 1)
for _ in range(M):
    steps[int(input())] = False
dp = [0] * (N + 1)
dp[0] = 1
for prev in range(N):
    for now in range(prev + 1, min(N, prev + 2) + 1):
        if steps[now]:
            dp[now] += dp[prev]
            dp[now] %= 1_000_000_007
print(dp[N])


Fixed submission:
N, M = map(int, input().split())
steps = [True] * (N + 1)
for _ in range(M):
    steps[int(input())] = False
dp = [0] * (N + 1)
dp[0] = 1
for prev in range(N):
    for now in range(prev + 1, min(N, prev + 2) + 1):
        if steps[now]:
            dp[now] += dp[prev]
            dp[now] %= 10**9 + 7
print(dp[N])
Problem p03013 (Python)

Buggy submission (status: Time Limit Exceeded):
mod = 10**9 + 7

n, m = list(map(int, input().split()))
a = [int(input()) for _ in range(m)]

dp = {}
for i in range(n + 1):
    dp[i] = 1
dp[1] = 0 if 1 in a else 1
for i in range(2, n + 1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i - 1] % mod + dp[i - 2] % mod
        dp[i] %= mod

print(dp[n] % mod)


Fixed submission:
mod = 10**9 + 7

n, m = list(map(int, input().split()))
a = set([int(input()) for _ in range(m)])

dp = {}
for i in range(n + 1):
    dp[i] = 1
dp[1] = 0 if 1 in a else 1
for i in range(2, n + 1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i - 1] % mod + dp[i - 2] % mod
        dp[i] %= mod

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

Buggy submission (status: Time Limit Exceeded):
import sys
import os

MOD = 10**9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    A = [int(sys.stdin.buffer.readline().rstrip()) for _ in range(M)]

    ret = [0, 1]
    for i in range(1, N + 1):
        if i in A:
            ret.append(0)
        else:
            ret.append((ret[-1] + ret[-2]) % MOD)

    print(ret[-1] % MOD)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import os

MOD = 10**9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    A = set([int(sys.stdin.buffer.readline().rstrip()) for _ in range(M)])

    ret = [0, 1]
    for i in range(1, N + 1):
        if i in A:
            ret.append(0)
        else:
            ret.append((ret[-1] + ret[-2]) % MOD)

    print(ret[-1] % MOD)


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

Buggy submission (status: Time Limit Exceeded):
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M] = list(map(lambda x: int(x), inputs[0].split()))
    broke_steps = list(map(lambda x: int(x), inputs[1:]))

    SSSS = 1000000007

    patterns = [1]
    for step in range(1, N + 1):
        if step in broke_steps:
            ap = 0
        elif step == 1:
            ap = 1
        else:
            ap = (patterns[step - 1] + patterns[step - 2]) % SSSS
        patterns.append(ap)

    return patterns[-1]


if __name__ == "__main__":
    first = input()
    [N, M] = list(map(lambda x: int(x), first.split()))
    inputs_str = inputs(M)
    inputs_str.insert(0, first)
    ret = solve(inputs_str)
    print(ret)


Fixed submission:
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M] = list(map(lambda x: int(x), inputs[0].split()))
    broke_steps = {}
    for b in map(lambda x: int(x), inputs[1:]):
        broke_steps[b] = True

    SSSS = 1000000007

    patterns = [1]
    for step in range(1, N + 1):
        if step in broke_steps:
            ap = 0
        elif step == 1:
            ap = 1
        else:
            ap = (patterns[step - 1] + patterns[step - 2]) % SSSS
        patterns.append(ap)

    return patterns[-1]


if __name__ == "__main__":
    first = input()
    [N, M] = list(map(lambda x: int(x), first.split()))
    inputs_str = inputs(M)
    inputs_str.insert(0, first)
    ret = solve(inputs_str)
    print(ret)
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())

A = []

for _ in range(M):
    A[int(input())] = True

step = [0] * (N + 1)

step[0] = 1

for s in range(1, N + 1):
    if A[s]:
        step[s] = 0
        continue
    if s == 1:
        step[s] = 1
        continue
    else:
        step[s] = step[s - 1] + step[s - 2]
        step[s] %= 1000000007

print(step[N])


Fixed submission:
N, M = map(int, input().split())

A = [False] * (N + 1)

for _ in range(M):
    A[int(input())] = True

step = [0] * (N + 1)

step[0] = 1

for s in range(1, N + 1):
    if A[s]:
        step[s] = 0
        continue
    if s == 1:
        step[s] = 1
        continue
    else:
        step[s] = step[s - 1] + step[s - 2]
        step[s] %= 1000000007

print(step[N])
Problem p03013 (Python)

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

stairs = []
is_continuous = False
for i in range(m):
    stairs.append(int(input()))
    if i > 0 and stairs[i] - 1 == stairs[i - 1]:
        is_continuous = True
        break

if is_continuous:
    print(0)
else:
    countup_num = [0] * (n + 1)
    countup_num[0] = 1
    countup_num[1] = 1
    for i in range(2, n + 1):
        countup_num[i] = (countup_num[i - 1] + countup_num[i - 2]) % 1000000007
    res = 1
    diff = 0
    now = 0
    for i in range(m):
        diff = stairs[i] - now - 1
        now = stairs[i] + 1
        res *= (countup_num[diff]) % 1000000007
        # print(res, now)
    diff = n - stairs[-1] - 1
    res *= (countup_num[diff]) % 1000000007

    res %= 1000000007
    # print(countup_num)
    print(res)


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

stairs = []
is_continuous = False
for i in range(m):
    stairs.append(int(input()))
    if i > 0 and stairs[i] - 1 == stairs[i - 1]:
        is_continuous = True
        break

if is_continuous:
    print(0)
else:
    countup_num = [0] * (n + 1)
    countup_num[0] = 1
    countup_num[1] = 1
    for i in range(2, n + 1):
        countup_num[i] = (countup_num[i - 1] + countup_num[i - 2]) % 1000000007
    res = 1
    diff = 0
    now = 0
    for i in range(m):
        diff = stairs[i] - now - 1
        now = stairs[i] + 1
        res *= (countup_num[diff]) % 1000000007
        # print(res, now)
    if m == 0:
        res = countup_num[n]
    else:
        diff = n - stairs[-1] - 1
        res *= (countup_num[diff]) % 1000000007

    res %= 1000000007
    # print(countup_num)
    print(res)
Problem p03013 (Python)

Buggy submission (status: Time Limit Exceeded):
div = 1000000007

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])


Fixed submission:
div = 1000000007

n, m, *b = map(int, open(0).read().split())
a = set(b)

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
def Fib(n, memo={}):
    if n < 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n]


def resolve():
    N, M = [int(i) for i in input().split()]
    aa = []
    for _ in range(M):
        aa.append(int(input()))
    fib_l = list(Fib(i) for i in range(N))

    ans = 1
    now = 0
    for a in aa:
        if now == a:
            ans = 0
            break
        tmp = a - now - 1
        ans = ans * fib_l[tmp]
        now = a + 1
    else:
        ans = ans * fib_l[N - now]
    print(ans % (10**9 + 7))


resolve()


Fixed submission:
def Fib(n, memo={}):
    if n < 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n]


def resolve():
    N, M = [int(i) for i in input().split()]
    aa = []
    for _ in range(M):
        aa.append(int(input()))
    fib_l = list(Fib(i) for i in range(N + 1))

    ans = 1
    now = 0
    for a in aa:
        if now == a:
            ans = 0
            break
        tmp = a - now - 1
        ans = ans * fib_l[tmp]
        now = a + 1
    else:
        ans = ans * fib_l[N - now]
    print(ans % (10**9 + 7))


resolve()
Problem p03013 (Python)

Buggy submission (status: Time Limit Exceeded):
N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
MOD = 10**9 + 7
dp = [1]
if 1 in a:
    dp.append(0)
else:
    dp.append(1)
for ith_stair in range(2, N + 1):
    if ith_stair in a:
        dp.append(0)
    else:
        dp.append((dp[ith_stair - 1] + dp[ith_stair - 2]) % MOD)
print(dp[N] % MOD)


Fixed submission:
N, M = map(int, input().split())
a = set([int(input()) for i in range(M)])
MOD = 10**9 + 7
dp = [1]
if 1 in a:
    dp.append(0)
else:
    dp.append(1)
for ith_stair in range(2, N + 1):
    if ith_stair in a:
        dp.append(0)
    else:
        dp.append((dp[ith_stair - 1] + dp[ith_stair - 2]) % MOD)
print(dp[N] % MOD)
Problem p03013 (Python)

Buggy submission (status: Runtime Error):
d = {}


def calc_step_combination(num):
    if num == 0:
        return 0
    if num == 1 or num == 2:
        return 1
    if num in d:
        return d[num]
    res = calc_step_combination(num - 1) + calc_step_combination(num - 2)
    d[num] = res
    return res


def sol(n, a_list):
    step_batch = []
    batch_start = 0
    for a in a_list:
        step_batch.append(a - batch_start)
        batch_start = a + 1
    step_batch.append(n - batch_start + 1)

    result = 1
    for i, steps in enumerate(step_batch):
        result *= calc_step_combination(steps)
    print(result % 1000000007)


def main():
    n, m = map(int, input().split())
    a_list = []
    for i in range(0, m):
        a_list.append(int(input()))
    sol(n, a_list)


main()


Fixed submission:
import sys

sys.setrecursionlimit(110000)

d = {}


def calc_step_combination(num):
    if num == 0:
        return 0
    if num == 1 or num == 2:
        return 1
    if num in d:
        return d[num]
    res = calc_step_combination(num - 1) + calc_step_combination(num - 2)
    d[num] = res
    return res


def sol(n, a_list):
    step_batch = []
    batch_start = 0
    for a in a_list:
        step_batch.append(a - batch_start)
        batch_start = a + 1
    step_batch.append(n - batch_start + 1)

    result = 1
    for i, steps in enumerate(step_batch):
        result *= calc_step_combination(steps)
    print(result % 1000000007)


def main():
    n, m = map(int, input().split())
    a_list = []
    for i in range(0, m):
        a_list.append(int(input()))
    sol(n, a_list)


main()
Problem p03013 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;

const int mx = 200010;
const ll mod = 1e9 + 7;

int n, m;
int a;
ll dp[mx];
bool dpflag[mx] = {true};

int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    dpflag[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    dpflag[a] = false;
  }

  dp[0] = 1;
  if (dpflag[1]) {
    dp[1] = 1;
  }
  for (int now = 0; now < n; now++) {
    for (int next = now + 1; next <= n; next++) {
      if (dpflag[next]) {
        dp[next] = dp[now] + dp[now - 1];
        dp[next] %= mod;
      }
    }
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;

const int mx = 200010;
const ll mod = 1e9 + 7;

int n, m;
int a;
ll dp[mx];
bool dpflag[mx] = {true};

int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    dpflag[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    dpflag[a] = false;
  }

  dp[0] = 1;
  if (dpflag[1]) {
    dp[1] = 1;
  }
  for (int next = 1; next <= n; next++) {
    if (dpflag[next + 1]) {
      dp[next + 1] = dp[next] + dp[next - 1];
      dp[next + 1] %= mod;
    }
  }

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

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

long long patterns(int a) {
  if (a == 0)
    return 1;
  else if (a == 1)
    return 1;
  else if (a == 2)
    return 2;
  else {
    return 2 * patterns(a - 2) + patterns(a - 3);
  }
}

int main() {
  int n, m, i, skip = 1;
  long long ans = 1;
  cin >> n >> m;

  vector<int> a(m);
  for (i = 0; i < m; i++) {
    cin >> a.at(i);
  }

  for (i = 1; i < m; i++) {
    if (a.at(i - 1) + 1 == a.at(i)) {
      ans = 0;
      skip = 0;
      break;
    }
  }

  if (m == 0) {
    ans = patterns(n);
    skip = 0;
  }

  if (m == 1) {
    ans = patterns(a.at(0) - 1) * patterns(n - a.at(0) - 1);
    skip = 0;
  }

  if (skip) {
    ans *= patterns(a.at(0) - 1);

    for (i = 1; i < m; i++) {
      ans *= patterns(a.at(i) - a.at(i - 1) - 2);
      ans = ans % 1000000007;
    }

    ans *= patterns(n - a.at(m - 1) - 1);
  }

  cout << ans % 1000000007 << endl;
}


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

long long patterns(int a) {
  if (a == 0)
    return 1;
  else if (a == 1)
    return 1;
  else if (a == 2)
    return 2;
  else if (a % 2 == 0) {
    return (patterns(a / 2) * patterns(a / 2) +
            patterns(a / 2 - 1) * patterns(a / 2 - 1)) %
           1000000007;
  } else {
    return (patterns(a / 2) * patterns(a / 2 + 1) +
            patterns(a / 2 - 1) * patterns(a / 2)) %
           1000000007;
  }
}

int main() {
  int n, m, i, skip = 1;
  long long ans = 1;
  cin >> n >> m;

  vector<int> a(m);
  for (i = 0; i < m; i++) {
    cin >> a.at(i);
  }

  for (i = 1; i < m; i++) {
    if (a.at(i - 1) + 1 == a.at(i)) {
      ans = 0;
      skip = 0;
      break;
    }
  }

  if (m == 0) {
    ans = patterns(n);
    skip = 0;
  }

  if (m == 1) {
    ans = patterns(a.at(0) - 1) * patterns(n - a.at(0) - 1);
    skip = 0;
  }

  if (skip) {
    ans *= patterns(a.at(0) - 1);

    for (i = 1; i < m; i++) {
      ans *= patterns(a.at(i) - a.at(i - 1) - 2);
      ans = ans % 1000000007;
    }

    ans *= patterns(n - a.at(m - 1) - 1);
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <map>
#include <math.h>
#include <unordered_map>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define lper(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
  ll N;
  ll M;
  cin >> N >> M;

  vl vec(M);
  rep(i, N + 1) {
    ll a;
    cin >> a;
    vec.at(a) = 1;
  }

  ll dp[N + 1];
  dp[0] = 1;
  if (vec.at(1) == 1) {
    dp[1] = 0;
  } else if (vec.at(1) != 1) {
    dp[1] = 1;
  }
  repl(i, 2, N + 1) {
    if (vec.at(i)) {
      dp[i] = 0;
      continue;
    } else {
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
  }
  cout << dp[N] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <map>
#include <math.h>
#include <unordered_map>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define lper(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9;
const ll INF = 4e18;
const ll dy[4] = {1, 0, -1, 0};
const ll dx[4] = {0, -1, 0, 1};
int main() {
  ll N;
  ll M;
  cin >> N >> M;

  vl vec(N + 1);
  rep(i, M) {
    ll a;
    cin >> a;
    vec.at(a) = 1;
  }

  ll dp[N + 1];
  dp[0] = 1;
  if (vec.at(1) == 1) {
    dp[1] = 0;
  } else if (vec.at(1) != 1) {
    dp[1] = 1;
  }
  repl(i, 2, N + 1) {
    if (vec.at(i)) {
      dp[i] = 0;
      continue;
    } else {
      dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
    }
  }
  cout << dp[N] << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

int64_t kRem = 1000000007;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<int> blocks(m);
  for (auto &block : blocks) {
    cin >> block;
  }

  vector<int64_t> scores(n + 1);
  scores[0] = 1;
  auto it = blocks.begin();
  if (*it == 1) {
    scores[1] = 0;
    it++;
  } else {
    scores[1] = 1;
  }

  FOR_LE(i, 2, n) {
    if (it != blocks.end() && *it == i) {
      scores[i] = 0;
      it++;
      continue;
    }

    scores[i] = scores[i - 1] + scores[i - 2];
    scores[i] %= kRem;
  }

  cout << scores[n] << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

int64_t kRem = 1000000007;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<int> blocks(m);
  for (auto &block : blocks) {
    cin >> block;
  }

  vector<int64_t> scores(n + 1);
  scores[0] = 1;
  auto it = blocks.begin();
  if (it != blocks.end() && *it == 1) {
    scores[1] = 0;
    it++;
  } else {
    scores[1] = 1;
  }

  FOR_LE(i, 2, n) {
    if (it != blocks.end() && *it == i) {
      scores[i] = 0;
      it++;
      continue;
    }

    scores[i] = scores[i - 1] + scores[i - 2];
    scores[i] %= kRem;
  }

  cout << scores[n] << endl;

  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
#define moju (long long int)(1e9 + 7)
using namespace std;
int main() {
  int n, m;
  int i;
  long long int c, ans = 1;
  cin >> n >> m;
  vector<long long int> a(m), b(n);
  for (i = 0; i < m; i++)
    cin >> a[i];
  for (i = 0; i < n; i++) {
    if (i <= 1)
      b[i] = i + (long long int)1;
    else
      b[i] = (b[i - 1] + b[i - 2]) % moju;
    // cout << b[i] << endl;
  }
  // cout << endl;
  for (i = 0; i <= m; i++) {
    if (i == 0)
      c = a[i] - 2;
    else if (i == m)
      c = n - a[i - 1] - 2;
    else
      c = a[i] - a[i - 1] - 3;

    if (c < 0)
      ans *= (c + 2);
    else
      ans = (ans * b[c]) % moju;
    // cout << ans << endl;
    // cout << b[c] << endl;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
#define moju (long long int)(1e9 + 7)
using namespace std;
int main() {
  int n, m;
  int i;
  long long int c, ans = 1;
  cin >> n >> m;
  if (m == 0) {
    vector<long long int> b(n);
    for (i = 0; i < n; i++) {
      if (i <= 1)
        b[i] = i + (long long int)1;
      else
        b[i] = (b[i - 1] + b[i - 2]) % moju;
      // cout << b[i] << endl;
    }
    cout << b[n - 1] << endl;
    return 0;
  }
  vector<long long int> a(m), b(n);
  for (i = 0; i < m; i++)
    cin >> a[i];
  for (i = 0; i < n; i++) {
    if (i <= 1)
      b[i] = i + (long long int)1;
    else
      b[i] = (b[i - 1] + b[i - 2]) % moju;
    // cout << b[i] << endl;
  }
  // cout << endl;
  for (i = 0; i <= m; i++) {
    if (i == 0)
      c = a[i] - 2;
    else if (i == m)
      c = n - a[i - 1] - 2;
    else
      c = a[i] - a[i - 1] - 3;

    if (c < 0)
      ans *= (c + 2);
    else
      ans = (ans * b[c]) % moju;
    // cout << ans << endl;
    // cout << b[c] << endl;
  }
  cout << ans << 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++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> dp(1001);
  unordered_map<int, int> dest{};
  vector<ll> a(M);
  REP(i, M) {
    cin >> a[i];
    dest[a[i]]++;
  }
  REP(i, dp.size()) dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (dest[i] != 0)
      continue;
    if (dest[i + 1] == 0) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD;
    }
    if (dest[i + 2] == 0) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD;
    }
  }
  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++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> dp(100110);
  unordered_map<int, int> dest{};
  vector<ll> a(M);
  REP(i, M) {
    cin >> a[i];
    dest[a[i]]++;
  }
  REP(i, dp.size()) dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (dest[i] != 0)
      continue;
    if (dest[i + 1] == 0) {
      dp[i + 1] += dp[i];
      dp[i + 1] %= MOD;
    }
    if (dest[i + 2] == 0) {
      dp[i + 2] += dp[i];
      dp[i + 2] %= MOD;
    }
  }
  cout << dp[N] << endl;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
std::vector<bool> stiustir;
std::vector<long long> recordstepstir;
int N = 0;
void search(int now) {
  long long step = 0;
  if (stiustir[now] == false) {
    recordstepstir[now] = 0;
    search(now - 1);
    return;
  }
  if (now > 0 && now <= N - 2) {
    step += recordstepstir[now + 2];
    step += recordstepstir[now + 1];
    recordstepstir[now] = step % 1000000007;
    search(now - 1);
  } else if (now == N - 1) {
    recordstepstir[now] = 1;
    search(now - 1);
    return;
  } else if (now == 0) {
    step += recordstepstir[now + 2];
    step += recordstepstir[now + 1];
    recordstepstir[now] = step % 1000000007;
    cout << (step % 1000000007);
    return;
  }
  return;
}
int main(void) {
  int i, j, k, M;
  cin >> N >> M;
  int a[M];
  for (i = 0; i < M; i++) {
    cin >> a[i];
  }
  for (i = 0; i < N; i++) {
    stiustir.push_back(true);
    recordstepstir.push_back(0);
  }
  recordstepstir.push_back(1);
  stiustir.push_back(true);
  for (i = 0; i < M; i++) {
    stiustir[a[i]] = false;
  }
  search(N - 1);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
std::vector<bool> stiustir;
std::vector<long long> recordstepstir;
int N = 0;
void search(int now) {
  long long step = 0;
  if (stiustir[now] == false) {
    recordstepstir[now] = 0;
    search(now - 1);
    return;
  }
  if (now > 0 && now <= N - 2) {
    step += recordstepstir[now + 2];
    step += recordstepstir[now + 1];
    recordstepstir[now] = step % 1000000007;
    search(now - 1);
  } else if (now == N - 1) {
    recordstepstir[now] = 1;
    search(now - 1);
    return;
  } else if (now == 0) {
    step += recordstepstir[now + 2];
    step += recordstepstir[now + 1];
    recordstepstir[now] = step % 1000000007;
    cout << (step % 1000000007);
    return;
  }
  return;
}
int main(void) {
  int i, j, k, M;
  cin >> N >> M;
  int a[M];
  for (i = 0; i < M; i++) {
    cin >> a[i];
  }
  for (i = 0; i < N; i++) {
    stiustir.push_back(true);
    recordstepstir.push_back(0);
  }
  recordstepstir.push_back(1);
  stiustir.push_back(true);
  for (i = 0; i < M; i++) {
    stiustir[a[i]] = false;
  }
  if (N == 1) {
    cout << 1;
    return 0;
  }
  search(N - 1);
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  vector<ll> dp(n + 5, 0);
  dp[0] = 1;
  dp[1] = (a[0] == 1) ? 0 : 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = max(dp[i], dp[i - 1] + dp[i - 2]) % MOD;
    for (int j = 0; j < m; j++) {
      if (i == a[j]) {
        dp[i] = 0;
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  vector<ll> dp(n + 5, 0);
  dp[0] = 1;
  dp[1] = 1;
  if (m != 0 and a[0] == 1) {
    dp[1] = 0;
  }

  for (int i = 2; i <= n; i++) {
    dp[i] = max(dp[i], dp[i - 1] + dp[i - 2]) % MOD;
    for (int j = 0; j < m; j++) {
      if (i == a[j]) {
        dp[i] = 0;
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
Problem p03013 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x)                                                                \
  for (auto itr : x) {                                                         \
    debug(itr);                                                                \
  }

template <class T> inline void chmax(T &ans, T t) {
  if (t > ans)
    ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
  if (t < ans)
    ans = t;
}

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, bool> mp;
  vector<ll> dp(n + 1, 0), a(m);
  rep(i, m) {
    cin >> a[i];
    mp[a[i]] += 1;
  }
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (mp[i]) {
      continue;
    }
    if (!mp[i + 1]) {
      dp[i + 1] += (dp[i]) % MOD;
      dp[i + 1] %= MOD;
    }
    if (!mp[i + 2]) {
      dp[i + 2] += (dp[i]) % MOD;
      dp[i + 2] %= MOD;
    }
  }

  cout << dp[n] << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x)                                                                \
  for (auto itr : x) {                                                         \
    debug(itr);                                                                \
  }

template <class T> inline void chmax(T &ans, T t) {
  if (t > ans)
    ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
  if (t < ans)
    ans = t;
}

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, bool> mp;
  vector<ll> dp(n + 10, 0), a(m + 2);
  rep(i, m) {
    cin >> a[i];
    mp[a[i]] += 1;
  }
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (mp[i]) {
      continue;
    }
    if (!mp[i + 1]) {
      dp[i + 1] += (dp[i]) % MOD;
      dp[i + 1] %= MOD;
    }
    if (!mp[i + 2]) {
      dp[i + 2] += (dp[i]) % MOD;
      dp[i + 2] %= MOD;
    }
  }

  cout << dp[n] << endl;
}
Problem p03013 (C++)

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

int kMod = 1e9 + 7;

void print_all(const std::vector<int> &v) {
  for (int x : v) {
    std::cout << x << '\n';
  }
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<bool> is_broken(n, false);
  for (int i = 0; i < m; i++) {
    int broken_index;
    std::cin >> broken_index;
    is_broken.at(broken_index - 1) = true;
  }
  std::vector<int> patterns(n, 0);
  if (is_broken.at(0)) {
    patterns.at(0) = 0;
  } else {
    patterns.at(0) = 1;
  }
  if (is_broken.at(1)) {
    patterns.at(1) = 0;
  } else {
    patterns.at(1) = patterns.at(0) + 1;
  }
  for (int i = 2; i < n; i++) {
    if (is_broken.at(i)) {
      patterns.at(i) = 0;
    } else {
      patterns.at(i) = (patterns.at(i - 1) + patterns.at(i - 2)) % kMod;
    }
  }
  std::cout << patterns.back() << '\n';
  // print_all(patterns);
  return 0;
}


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

int kMod = 1e9 + 7;

void print_all(const std::vector<int> &v) {
  for (int x : v) {
    std::cout << x << '\n';
  }
}

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<bool> is_broken(n, false);
  for (int i = 0; i < m; i++) {
    int broken_index;
    std::cin >> broken_index;
    is_broken.at(broken_index - 1) = true;
  }
  std::vector<int> patterns(n, 0);
  if (is_broken.at(0)) {
    patterns.at(0) = 0;
  } else {
    patterns.at(0) = 1;
  }
  if (n <= 1) {
    std::cout << patterns.at(0) << '\n';
    return 0;
  }
  if (is_broken.at(1)) {
    patterns.at(1) = 0;
  } else {
    patterns.at(1) = patterns.at(0) + 1;
  }
  for (int i = 2; i < n; i++) {
    if (is_broken.at(i)) {
      patterns.at(i) = 0;
    } else {
      patterns.at(i) = (patterns.at(i - 1) + patterns.at(i - 2)) % kMod;
    }
  }
  std::cout << patterns.back() << '\n';
  // print_all(patterns);
  return 0;
}