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

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

using namespace std;

#define MOD 1000000007

int N;
int a[10000];

long long power(int m) {
  long long sum = 1;
  long long s = 2;
  while (m != 0) {
    if (m % 2 == 1)
      sum *= s;
    s *= s;
    m /= 2;
    s %= MOD;
    sum %= MOD;
  }
  return sum;
}

int main() {
  int n;
  cin >> N;
  for (int i = 0; i < N; i++)
    a[i] = 0;
  for (int i = 0; i < N; i++) {
    cin >> n;
    a[n]++;
  }
  if (N % 2 == 1) {
    if (a[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 1; i < N; i++) {
      if (i % 2 == 1) {
        if (a[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(N / 2) << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (i % 2 == 1) {
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (a[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(N / 2) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

#define MOD 1000000007

int N;
int a[100000];

long long power(int m) {
  long long sum = 1;
  long long s = 2;
  while (m != 0) {
    if (m % 2 == 1)
      sum *= s;
    s *= s;
    m /= 2;
    s %= MOD;
    sum %= MOD;
  }
  return sum;
}

int main() {
  int n;
  cin >> N;
  for (int i = 0; i < N; i++)
    a[i] = 0;
  for (int i = 0; i < N; i++) {
    cin >> n;
    a[n]++;
  }
  if (N % 2 == 1) {
    if (a[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 1; i < N; i++) {
      if (i % 2 == 1) {
        if (a[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(N / 2) << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (i % 2 == 1) {
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (a[i] != 0) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(N / 2) << endl;
  }
  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;

const int MOD = 1000000000 + 7;
int vs[105];

int hist[100000 + 10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    hist[vs[i]]++;
    if ((n % 2 == vs[i] % 2) || hist[0] > 1 || hist[vs[i]] > 2) {
      puts("0");
      return 0;
    }
  }
  ll res = 1;
  REP(i, n / 2) {
    res *= 2;
    res %= MOD;
  }
  printf("%lld\n", res);

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;

const int MOD = 1000000000 + 7;
int vs[100005];

int hist[100000 + 10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    hist[vs[i]]++;
    if ((n % 2 == vs[i] % 2) || hist[0] > 1 || hist[vs[i]] > 2) {
      puts("0");
      return 0;
    }
  }
  ll res = 1;
  REP(i, n / 2) {
    res *= 2;
    res %= MOD;
  }
  printf("%lld\n", res);

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> cnt(N, 0);
  cnt[0] = 1;
  for (int i = 1; N - 2 * i < 0; i++) {
    cnt[N - 2 * i] = 2;
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    cnt[A]++;
    if (cnt[A] > 2) {
      cout << 0 << endl;
      return 0;
    } else if (cnt[A] == 1) {
      ans *= 2;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

long long MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> cnt(N, 0);
  cnt[0] = 1;
  for (int i = 1; N - 2 * i > 0; i++) {
    cnt[N - 2 * i] = 2;
  }

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    cnt[A]++;
    if (cnt[A] > 2) {
      cout << 0 << endl;
      return 0;
    } else if (cnt[A] == 1) {
      ans *= 2;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
Problem p03846 (C++)

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

ll mod = 1000000007;

ll modpow(ll a, ll b) {
  ll c = 1;
  while (b > 0) {
    if (b % 2 == 0) {
      b /= 2;
      a = (a * a) % mod;
    } else {
      b--;
      c = (c * a) % mod;
    }
  }
  return c;
}

int main() {
  // freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll i, j, k, t, n, a[10000] = {0};
  cin >> n;
  bool q = true;
  for (i = 0; i < n; i++) {
    cin >> t;
    a[t]++;
  }
  for (i = (n + 1) % 2; i < n; i += 2) {
    if (i == 0 && a[i] != 1) {
      q = false;
      break;
    }
    if (i > 0 && a[i] != 2) {
      q = false;
      break;
    }
  }
  if (q == false) {
    cout << "0";
  } else {
    n /= 2;
    cout << modpow(2, n);
  }
  return 0;
}

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

ll mod = 1000000007;

ll modpow(ll a, ll b) {
  ll c = 1;
  while (b > 0) {
    if (b % 2 == 0) {
      b /= 2;
      a = (a * a) % mod;
    } else {
      b--;
      c = (c * a) % mod;
    }
  }
  return c;
}

int main() {
  // freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll i, j, k, t, n, a[100000] = {0};
  cin >> n;
  bool q = true;
  for (i = 0; i < n; i++) {
    cin >> t;
    a[t]++;
  }
  for (i = (n + 1) % 2; i < n; i += 2) {
    if (i == 0 && a[i] != 1) {
      q = false;
      break;
    }
    if (i > 0 && a[i] != 2) {
      q = false;
      break;
    }
  }
  if (q == false) {
    cout << "0";
  } else {
    n /= 2;
    cout << modpow(2, n);
  }
  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a, n)                                                          \
  for (int i = 0; i < n; i++) {                                                \
    cin >> a[i];                                                               \
  }
#define N 55
const int MOD = 1000000007;
using namespace std;
unordered_map<int, bool> done;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

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

  int n;
  cin >> n;
  int num[n];
  arrayin(num, n) int person[n + 1];
  for (int i = 0; i <= n; i++)
    person[i] = 0;

  bool hoga = true;

  for (int i = 0; i < n; i++) {
    person[num[i]]++;
  }

  if (person[0] > 1) {
    hoga = false;
  }

  if (n & 1) {
    for (int i = n - 1; i >= 0; i -= 2) {
      if (person[i] > 2) {
        hoga = false;
      }
    }
  } else {
    for (int i = n - 1; i >= 1; i -= 2) {
      if (person[i] > 2) {
        hoga = false;
      }
    }
  }

  if (hoga) {
    int res = 1;

    for (int i = 0; i < n; i++) {
      int temp = num[i];
      if (done[temp]) {
        continue;
      } else {
        if (temp != 0) {
          res = res * 2;
          res %= MOD;
          done[temp] = true;
        }
      }
    }

    cout << res << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Fixed submission:
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a, n)                                                          \
  for (int i = 0; i < n; i++) {                                                \
    cin >> a[i];                                                               \
  }
#define N 55
const int MOD = 1000000007;
using namespace std;
unordered_map<int, bool> done;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  int num[n];
  arrayin(num, n) int person[n + 1];
  for (int i = 0; i <= n; i++)
    person[i] = 0;

  bool hoga = true;

  for (int i = 0; i < n; i++) {
    person[num[i]]++;
  }

  if (person[0] > 1) {
    hoga = false;
  }

  if (n & 1) {
    for (int i = n - 1; i >= 0; i -= 2) {
      if (person[i] > 2) {
        hoga = false;
      }
    }
  } else {
    for (int i = n - 1; i >= 1; i -= 2) {
      if (person[i] > 2) {
        hoga = false;
      }
    }
  }

  if (hoga) {
    int res = 1;

    for (int i = 0; i < n; i++) {
      int temp = num[i];
      if (done[temp]) {
        continue;
      } else {
        if (temp != 0) {
          res = res * 2;
          res %= MOD;
          done[temp] = true;
        }
      }
    }

    cout << res << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

signed main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) { cin >> a[i]; }
  int cnt[10100] = {};
  if (n % 2 == 1) {
    REP(i, n) {
      if (a[i] % 2 == 1) {
        cout << 0 << endl;
        return 0;
      }
      cnt[a[i]]++;
    }
    if (cnt[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    ll ans = 1;
    for (int i = 2; i < n; i += 2) {
      if (cnt[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      ans *= 2;
      ans %= MOD;
    }
    cout << ans << endl;
  } else {
    REP(i, n) {
      if (a[i] % 2 == 0) {
        cout << 0 << endl;
        return 0;
      }
      cnt[a[i]]++;
    }
    ll ans = 1;
    for (int i = 1; i < n; i += 2) {
      if (cnt[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      ans *= 2;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

signed main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) { cin >> a[i]; }
  int cnt[100000] = {};
  if (n % 2 == 1) {
    REP(i, n) {
      if (a[i] % 2 == 1) {
        cout << 0 << endl;
        return 0;
      }
      cnt[a[i]]++;
    }
    if (cnt[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    ll ans = 1;
    for (int i = 2; i < n; i += 2) {
      if (cnt[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      ans *= 2;
      ans %= MOD;
    }
    cout << ans << endl;
  } else {
    REP(i, n) {
      if (a[i] % 2 == 0) {
        cout << 0 << endl;
        return 0;
      }
      cnt[a[i]]++;
    }
    ll ans = 1;
    for (int i = 1; i < n; i += 2) {
      if (cnt[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      ans *= 2;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
Problem p03846 (C++)

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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

ll power(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return ans;
}

int main() {
  ll N, a[10000]{};
  cin >> N;
  for (int i = 0; i < N; i++) {
    ll b;
    cin >> b;
    if (b % 2 != (N + 1) % 2) {
      cout << 0 << endl;
      return 0;
    }
    a[b / 2]++;
  }
  a[0] += N % 2;
  for (int i = 0; i <= (N - 1) / 2; i++) {
    if (a[i] != 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << power(2, N / 2) << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

ll power(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return ans;
}

int main() {
  ll N, a[60000]{};
  cin >> N;
  for (int i = 0; i < N; i++) {
    ll b;
    cin >> b;
    if (b % 2 != (N + 1) % 2) {
      cout << 0 << endl;
      return 0;
    }
    a[b / 2]++;
  }
  a[0] += N % 2;
  for (int i = 0; i <= (N - 1) / 2; i++) {
    if (a[i] != 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << power(2, N / 2) << endl;
  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;

const int rdigit = 30;
const ll MOD = 1E+09 + 7;
const ll R = 1LL << rdigit;
const ll modRmask = (1LL << (rdigit + 1)) - 1;
const ll R2 = (R * R) % MOD;
const ll Y = 79133769;

ll MR(ll T);
ll MGmodPow(ll x, ll a);

const int MAX_N = 100000;

ll N;
ll A[MAX_N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;

  unordered_map<ll, int> mp;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (mp.count(A[i])) {
      mp[A[i]]++;
    } else {
      mp.insert(make_pair(A[i], 1));
    }
  }

  bool isPossible = true;

  ll j = !(N & 1);

  for (; j <= N - 1; j += 2) {
    if (mp.count(j)) {
      if (mp[j] != 2 && !(j == 0 && mp[j] == 1)) {
        isPossible = false;
      }
    } else {
      isPossible = false;
    }
  }

  ll ans;

  if (isPossible) {
    ans = MR(MGmodPow(MR(2 * R2), N / 2));
  } else {
    ans = 0;
  }

  cout << ans << "\n";

  return 0;
}

ll MR(ll T) {
  ll t = (T + ((T * Y) & modRmask) * MOD) >> rdigit;
  if (t >= MOD) {
    return t - MOD;
  } else {
    return t;
  }
}

ll MGmodPow(ll x, ll a) {
  if (a == 1)
    return x;
  if (a % 2 == 0) {
    ll t = MGmodPow(x, a / 2);
    return MR(t * t);
  } else {
    return MR(x * MGmodPow(x, a - 1));
  }
}

Fixed submission:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;

const int rdigit = 30;
const ll MOD = 1E+09 + 7;
const ll R = 1LL << rdigit;
const ll modRmask = (1LL << (rdigit + 1)) - 1;
const ll R2 = (R * R) % MOD;
const ll Y = 79133769;

ll MR(ll T);
ll MGmodPow(ll x, ll a);

const int MAX_N = 100000;

ll N;
ll A[MAX_N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;

  unordered_map<ll, int> mp;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (mp.count(A[i])) {
      mp[A[i]]++;
    } else {
      mp.insert(make_pair(A[i], 1));
    }
  }

  bool isPossible = true;

  ll j = !(N & 1);

  for (; j <= N - 1; j += 2) {
    if (mp.count(j)) {
      if (mp[j] != 2 && !(j == 0 && mp[j] == 1)) {
        isPossible = false;
      }
    } else {
      isPossible = false;
    }
  }

  ll ans;

  if (isPossible) {
    ans = MR(MGmodPow(MR(2 * R2), N / 2));
  } else {
    ans = 0;
  }

  cout << ans << "\n";

  return 0;
}

ll MR(ll T) {
  ll t = (T + ((T * Y) & modRmask) * MOD) >> rdigit;
  if (t >= MOD) {
    return t - MOD;
  } else {
    return t;
  }
}

ll MGmodPow(ll x, ll a) {
  if (a == 0)
    return MR(R2);
  if (a == 1)
    return x;
  if (a % 2 == 0) {
    ll t = MGmodPow(x, a / 2);
    return MR(t * t);
  } else {
    return MR(x * MGmodPow(x, a - 1));
  }
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll, ll>
#define INF 1000000000000000000

// using namespace atcoder;
using namespace std;

ll power(ll n, ll k) {
  ll res = 1;
  while (k > 0) {
    if (k & 1)
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<ll> hoge(n / 2, 2);
  if (n % 2 == 1)
    hoge[0]--;

  int ok = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0 && n % 2 == 0)
      ok = 0;
    if (a[i] % 2 == 1 && n % 2 == 1)
      ok = 0;

    hoge[a[i] / 2]--;
  }

  for (int i = 0; i < n / 2; i++) {
    if (hoge[i] != 0)
      ok = 0;
  }
  if (ok) {
    cout << power(2, n / 2) << endl;
  } else
    cout << 0 << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll, ll>
#define INF 1000000000000000000

// using namespace atcoder;
using namespace std;

ll power(ll n, ll k) {
  ll res = 1;
  while (k > 0) {
    if (k & 1)
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;

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

  vector<ll> hoge((n + 1) / 2, 2);

  if (n % 2 == 1)
    hoge[0]--;

  int ok = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0 && n % 2 == 0)
      ok = 0;
    if (a[i] % 2 == 1 && n % 2 == 1)
      ok = 0;

    hoge[a[i] / 2]--;
  }

  for (int i = 0; i < n / 2; i++) {
    if (hoge[i] != 0)
      ok = 0;
  }
  if (ok) {
    cout << power(2, n / 2) << endl;
  } else
    cout << 0 << endl;

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;

const int INF = 1000000007;

using namespace std;

// 入力
#define MAX_N 1000
int N;
int A[MAX_N];
int B[MAX_N + 1];

// n ^ k mod m
long long powmod(int n, int k, int m) {

  if (k == 0) {
    return 1;
  } else if (k % 2 != 0) {
    return (n * powmod(n, k - 1, m)) % m;
  } else {
    long long x = powmod(n, k / 2, m);
    return x * x % m;
  }
}

int main() {
  ios::sync_with_stdio(false);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A + N);

  bool correct = true;
  int i, num;
  if (N % 2 != 0) {
    correct &= (A[0] == 0);
    i = 1;
    num = 2;
  } else {
    i = 0;
    num = 1;
  }
  while (i < N) {
    correct &= (A[i] == num);
    correct &= (A[i + 1] == num);
    num += 2;
    i += 2;
  }

  if (!correct) {
    cout << 0 << endl;
  } else {
    cout << powmod(2, N / 2, INF) << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;

const int INF = 1000000007;

using namespace std;

// 入力
#define MAX_N 100000
int N;
int A[MAX_N];
int B[MAX_N + 1];

// n ^ k mod m
long long powmod(int n, int k, int m) {

  if (k == 0) {
    return 1;
  } else if (k % 2 != 0) {
    return (n * powmod(n, k - 1, m)) % m;
  } else {
    long long x = powmod(n, k / 2, m);
    return x * x % m;
  }
}

int main() {
  ios::sync_with_stdio(false);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  sort(A, A + N);

  bool correct = true;
  int i, num;
  if (N % 2 != 0) {
    correct &= (A[0] == 0);
    i = 1;
    num = 2;
  } else {
    i = 0;
    num = 1;
  }
  while (i < N) {
    correct &= (A[i] == num);
    correct &= (A[i + 1] == num);
    num += 2;
    i += 2;
  }

  if (!correct) {
    cout << 0 << endl;
  } else {
    cout << powmod(2, N / 2, INF) << endl;
  }

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef long long ll;

signed main() {

  int n, a[11111];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = n % 2; i < n; i += 2) {
    if (a[i] != a[i + 1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (n % 2 == 1)
    n -= 1;
  int ans = 1;
  for (int i = 0; i < n / 2; i++) {
    ans *= 2;
    ans %= 1000000007;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef long long ll;

signed main() {

  int n, a[111111];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = n % 2; i < n; i += 2) {
    if (a[i] != a[i + 1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  if (n % 2 == 1)
    n -= 1;
  int ans = 1;
  for (int i = 0; i < n / 2; i++) {
    ans *= 2;
    ans %= 1000000007;
  }
  cout << ans << endl;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int sx, sy, tx, ty;
int main() {
  int n;
  int a[11000] = {};
  int tmp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a[tmp]++;
  }
  if (n % 2 == 0) {
    for (int i = 1; i < n; i += 2)
      if (a[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
  } else {
    if (a[0] != 1) {
      cout << 0 << endl;
      return 0;
    } else
      for (int i = 2; i < n; i += 2)
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
  }
  long long an = 1;
  for (int i = 0; i < n / 2; i++) {
    an *= 2;
    an %= (long long)1e9 + 7;
  }
  cout << an << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int sx, sy, tx, ty;
int main() {
  int n;
  int a[110000] = {};
  int tmp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a[tmp]++;
  }
  if (n % 2 == 0) {
    for (int i = 1; i < n; i += 2)
      if (a[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
  } else {
    if (a[0] != 1) {
      cout << 0 << endl;
      return 0;
    } else
      for (int i = 2; i < n; i += 2)
        if (a[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
  }
  long long an = 1;
  for (int i = 0; i < n / 2; i++) {
    an *= 2;
    an %= (long long)1e9 + 7;
  }
  cout << an << endl;
}
Problem p03846 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const ll mod = 1e9 + 7;

ll modpow(ll a, ll n) {
  if (n == 1)
    return a;
  else if (n % 2)
    return a * modpow(a * a % mod, (n - 1) / 2) % mod;
  else
    return modpow(a * a % mod, n / 2);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  bool flag = 1;
  if (n % 2) {
    rep(i, n) {
      if (i == 0) {
        if (a[i] != 0)
          flag = 0;
      } else {
        if (a[i] != (i + 1) / 2 * 2)
          flag = 0;
      }
    }
  } else {
    rep(i, n) {
      if (a[i] != (i + 2) / 2 * 2 - 1)
        flag = 0;
    }
  }
  if (flag)
    cout << modpow(2, n / 2) << endl;
  else
    cout << 0 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

const ll mod = 1e9 + 7;

ll modpow(ll a, ll n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a;
  else if (n % 2)
    return a * modpow(a * a % mod, (n - 1) / 2) % mod;
  else
    return modpow(a * a % mod, n / 2);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  bool flag = 1;
  if (n % 2) {
    rep(i, n) {
      if (i == 0) {
        if (a[i] != 0)
          flag = 0;
      } else {
        if (a[i] != (i + 1) / 2 * 2)
          flag = 0;
      }
    }
  } else {
    rep(i, n) {
      if (a[i] != (i + 2) / 2 * 2 - 1)
        flag = 0;
    }
  }
  if (flag)
    cout << modpow(2, n / 2) << endl;
  else
    cout << 0 << endl;
  return 0;
}
Problem p03847 (C++)

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<ll, ll> p;

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

unordered_map<ll, ll> dp;

ll f(ll n) {
  if (n == 0)
    return 0;
  if (n == 1)
    return 1;
  return dp[n] = (f(n / 2) + f((n + 1) / 2) + f((n - 1) / 2)) % INF;
}

int main() {
  ios::sync_with_stdio(false);

  //    愚直解法 1 ~ 128
  //    set<p> s;
  //    ll pre = 1;
  //    //for(int N = 1; N <= 128; N*=2) {
  //    REP(N,1000) {
  //        s.clear();
  //        REP(a,N+1) REP(b,N+1) {
  //            ll u = a xor b;
  //            ll v = a + b;
  //            if (u<=N && v <=N)
  //                s.insert(p(u,v));
  //        }
  //        cout << "N: " << N << " ";
  //        cout << "size: " << s.size() << endl;
  //        //cout << "diff: " << s.size() - pre << endl;
  //        pre = s.size();
  //    }
  //    for(auto x: s){
  //        cout << x.first << " " << x.second << endl;
  //    }

  ll N;
  cin >> N;
  cout << f(N + 1) << endl;

  return 0;
}

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, n, m) for (ll i = n; i < (ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<ll, ll> p;

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

unordered_map<ll, ll> dp;

ll f(ll n) {
  if (n == 0)
    return 0;
  if (n == 1)
    return 1;
  if (dp.find(n) != dp.end())
    return dp[n];
  return dp[n] = (f(n / 2) + f((n + 1) / 2) + f((n - 1) / 2)) % INF;
}

int main() {
  ios::sync_with_stdio(false);

  //    愚直解法 1 ~ 128
  //    set<p> s;
  //    ll pre = 1;
  //    //for(int N = 1; N <= 128; N*=2) {
  //    REP(N,1000) {
  //        s.clear();
  //        REP(a,N+1) REP(b,N+1) {
  //            ll u = a xor b;
  //            ll v = a + b;
  //            if (u<=N && v <=N)
  //                s.insert(p(u,v));
  //        }
  //        cout << "N: " << N << " ";
  //        cout << "size: " << s.size() << endl;
  //        //cout << "diff: " << s.size() - pre << endl;
  //        pre = s.size();
  //    }
  //    for(auto x: s){
  //        cout << x.first << " " << x.second << endl;
  //    }

  ll N;
  cin >> N;
  cout << f(N + 1) << endl;

  return 0;
}
Problem p03847 (C++)

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

const int MOD = 1e9 + 7;

map<long long, int> m;
ll getAns(int dir) {
  if (m[dir])
    return m[dir];
  return m[dir] =
             (getAns(dir - 2 >> 1) + getAns(dir - 1 >> 1) + getAns(dir >> 1)) %
             MOD;
}

int main() {
  m[0] = 1;
  m[1] = 2;
  long long N;
  cin >> N;
  cout << getAns(N);
  return 0;
}

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

const int MOD = 1e9 + 7;

map<long long, int> m;
ll getAns(long long dir) {
  if (m[dir])
    return m[dir];
  return m[dir] =
             (getAns(dir - 2 >> 1) + getAns(dir - 1 >> 1) + getAns(dir >> 1)) %
             MOD;
}

int main() {
  m[0] = 1;
  m[1] = 2;
  long long N;
  cin >> N;
  cout << getAns(N);
  return 0;
}
Problem p03847 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long i64;
typedef pair<i64, i64> pi64;
const int MOD = 1e9 + 7;

i64 N;
map<i64, i64> dp;

i64 getDP(int x) {
  if (dp[x])
    return dp[x];
  dp[x] = (getDP(x / 2) + getDP((x - 1) / 2) + getDP((x - 2) / 2)) % MOD;
  return dp[x];
}

int main() {
  dp[0] = 1;
  dp[1] = 2;
  // cin >> N ;
  // cout << getDP(N) << endl ;
  scanf("%lld", &N);
  printf("%lld\n", getDP(N));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

typedef long long i64;
typedef pair<i64, i64> pi64;
const int MOD = 1e9 + 7;

i64 N;
map<i64, i64> dp;

i64 getDP(i64 x) {
  if (dp[x])
    return dp[x];
  dp[x] = (getDP(x / 2) + getDP((x - 1) / 2) + getDP((x - 2) / 2)) % MOD;
  return dp[x];
}

int main() {
  dp[0] = 1;
  dp[1] = 2;
  // cin >> N ;
  // cout << getDP(N) << endl ;
  scanf("%lld", &N);
  printf("%lld\n", getDP(N));
  return 0;
}
Problem p03847 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;
map<ll, ll> dp;

ll solve(ll x) {
  if (dp[x])
    return dp[x];
  return dp[x] = (solve(x / 2LL) + solve((x - 1LL) / 2LL) +
                  solve((x - 2LL) / 2LL)) %
                 mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  cout << solve(n) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;
map<ll, ll> dp;

ll solve(ll x) {
  if (dp[x])
    return dp[x];
  return dp[x] = (solve(x / 2LL) + solve((x - 1LL) / 2LL) +
                  solve((x - 2LL) / 2LL)) %
                 mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  dp[0] = 1;
  dp[1] = 2;

  cout << solve(n) << endl;
  return 0;
}
Problem p03848 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long ll;
ll N, a;
ll A[100010] = {0};
ll inf = 1e9 + 7;

ll mult(ll n, ll m) {
  if (m == 1)
    return n % inf;
  else if (m % 2 == 0) {
    ll t = mult(n, m / 2);
    return (t * t) % inf;
  } else {
    ll t = mult(n, m - 1);
    return (n * t) % inf;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A[a]++;
  }
  if (N % 2 == 1) {
    bool judge = true;
    for (int i = 0; i <= N / 2; i++) {
      if (i == 0 && A[i] != 1)
        judge = false;
      if (i != 0 && A[i * 2] != 2)
        judge = false;
    }
    if (judge)
      cout << mult(2, N / 2) << endl;
    else
      cout << 0 << endl;
  } else {
    bool judge = true;
    for (int i = 0; i < N / 2; i++) {
      if (A[i * 2 + 1] != 2)
        judge = false;
    }
    if (judge)
      cout << mult(2, N / 2) << endl;
    else
      cout << 0 << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;
ll N, a;
ll A[100010] = {0};
ll inf = 1e9 + 7;

ll mult(ll n, ll m) {
  if (m == 0)
    return 1;
  else if (m == 1)
    return n % inf;
  else if (m % 2 == 0) {
    ll t = mult(n, m / 2);
    return (t * t) % inf;
  } else {
    ll t = mult(n, m - 1);
    return (n * t) % inf;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A[a]++;
  }
  if (N % 2 == 1) {
    bool judge = true;
    for (int i = 0; i <= N / 2; i++) {
      if (i == 0 && A[i] != 1)
        judge = false;
      if (i != 0 && A[i * 2] != 2)
        judge = false;
    }
    if (judge)
      cout << mult(2, N / 2) << endl;
    else
      cout << 0 << endl;
  } else {
    bool judge = true;
    for (int i = 0; i < N / 2; i++) {
      if (A[i * 2 + 1] != 2)
        judge = false;
    }
    if (judge)
      cout << mult(2, N / 2) << endl;
    else
      cout << 0 << endl;
  }
}
Problem p03848 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin


def resolve():
    n = int(stdin.readline().rstrip())
    # s = stdin.readline().rstrip()
    # A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
    a = [int(x) for x in stdin.readline().rstrip().split()]

    a = sorted(a)
    if n % 2 == 1:
        if a[0] != 0:
            return 0
        a = a[1:]

    predict = 1 + (n % 2)
    while len(a) > 0:
        if a[0] != predict or a[1] != predict:
            return 0
        a = a[2:]
        predict += 2

    ret = 1
    for i in range(0, n // 2):
        ret = (ret * 2) % 1000000007
    return ret


print(resolve(), "\n")
# print(*data, sep='\n')


Fixed submission:
from sys import stdin


def resolve():
    n = int(stdin.readline().rstrip())
    # s = stdin.readline().rstrip()
    # A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
    a = [int(x) for x in stdin.readline().rstrip().split()]

    a = sorted(a)
    predict = [n - (((n - i + 1) // 2) * 2) + 1 for i in range(0, n)]
    if a != predict:
        return 0

    ret = 1
    for i in range(0, n // 2):
        ret = (ret * 2) % 1000000007
    return ret


print(resolve(), "\n")
# print(*data, sep='\n')
Problem p03848 (C++)

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

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll pow(int a, int n) {
  if (n == 0) {
    return 1;
  }

  if (n % 2 == 0) {
    return (pow(a, n / 2) * pow(a, n / 2) % mod);
  } else {
    return ((pow(a, n / 2) * pow(a, n / 2) % mod) * a % mod);
  }
}

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

  ll A[10000];
  map<ll, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }

  int P = N / 2;
  bool isValid = true;
  if (N % 2 == 0) {
    if (mp.size() != P) {
      isValid = false;
    }
    for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->second != 2) {
        isValid = false;
      }
    }
  } else {
    if (mp.size() != P + 1) {
      isValid = false;
    }
    for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->first == 0) {
        if (it->second != 1) {
          isValid = false;
        }
      } else {
        if (it->second != 2) {
          isValid = false;
        }
      }
    }
  }

  if (!isValid) {
    cout << 0 << endl;
  } else {
    cout << pow(2, P) % mod << endl;
  }

  return 0;
}

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

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

ll pow(int a, int n) {
  if (n == 0) {
    return 1;
  }

  if (n % 2 == 0) {
    return (pow(a, n / 2) * pow(a, n / 2) % mod);
  } else {
    return ((pow(a, n / 2) * pow(a, n / 2) % mod) * a % mod);
  }
}

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

  ll A[100000];
  map<ll, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }

  int P = N / 2;
  bool isValid = true;
  if (N % 2 == 0) {
    if (mp.size() != P) {
      isValid = false;
    }
    for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->second != 2) {
        isValid = false;
      }
    }
  } else {
    if (mp.size() != P + 1) {
      isValid = false;
    }
    for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      if (it->first == 0) {
        if (it->second != 1) {
          isValid = false;
        }
      } else {
        if (it->second != 2) {
          isValid = false;
        }
      }
    }
  }

  if (!isValid) {
    cout << 0 << endl;
  } else {
    cout << pow(2, P) % mod << endl;
  }

  return 0;
}
Problem p03848 (C++)

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

#define ll long long

ll MOD = 1000000007;

ll Power(ll a, ll n) {
  if (n == 1)
    return a;
  return ((a * Power(a, n - 1)) % MOD);
}

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

  map<int, int> Map;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;

    Map[x]++;
  }

  if (N % 2) {
    for (auto x : Map) {
      if (x.first == 0) {
        if (x.second != 1) {
          cout << 0 << endl;
          return 0;
        }
      } else if (x.first <= N - 1 && x.first % 2 == 0) {
        if (x.second != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << Power(2, N / 2) << endl;
  } else {
    for (auto x : Map) {
      if (x.first <= N - 1 && x.first % 2 == 1) {
        if (x.second != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << Power(2, N / 2) << endl;
  }
}

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

#define ll long long

ll MOD = 1000000007;

ll Power(ll a, ll n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return a;
  return ((a * Power(a, n - 1)) % MOD);
}

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

  map<int, int> Map;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;

    Map[x]++;
  }

  if (N % 2) {
    for (auto x : Map) {
      if (x.first == 0) {
        if (x.second != 1) {
          cout << 0 << endl;
          return 0;
        }
      } else if (x.first <= N - 1 && x.first % 2 == 0) {
        if (x.second != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << Power(2, N / 2) << endl;
  } else {
    for (auto x : Map) {
      if (x.first <= N - 1 && x.first % 2 == 1) {
        if (x.second != 2) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << Power(2, N / 2) << endl;
  }
}
Problem p03848 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long int
#define pll pair<double, ll>

int n;
int p[1000];
int c[100001];
ll mod = (ll)(1e9 + 7);

ll calc(int a) {
  ll r = 1;
  for (int i = 0; i < a; i++) {
    r *= 2;
    r %= mod;
  }
  return r;
}

int main() {
  fill(c, c + 100001, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    c[p[i]]++;
  }
  if (n % 2 == 1) {
    if (c[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 2; i <= n / 2; i += 2) {
      if (c[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << calc(n / 2) << endl;
    return 0;
  } else {
    for (int i = 1; i <= n / 2 + 1; i += 2) {
      if (c[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << calc(n / 2) << endl;
    return 0;
  }
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long int
#define pll pair<double, ll>

int n;
int p[100001];
int c[100001];
ll mod = (ll)(1e9 + 7);

ll calc(int a) {
  ll r = 1;
  for (int i = 0; i < a; i++) {
    r *= 2;
    r %= mod;
  }
  return r;
}

int main() {
  fill(c, c + 100001, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    c[p[i]]++;
  }
  if (n % 2 == 1) {
    if (c[0] != 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 2; i <= n / 2; i += 2) {
      if (c[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << calc(n / 2) << endl;
    return 0;
  } else {
    for (int i = 1; i <= n / 2 + 1; i += 2) {
      if (c[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    cout << calc(n / 2) << endl;
    return 0;
  }
}
Problem p03848 (C++)

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

const long long int mod = 1e9 + 7;
const long long int limit = 1e5;

int a[limit];
bool check[limit];

#define p(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

long long int get2(long long int n) {
  if (n == 1)
    return 2;
  else
    return (2 * (get2(n - 1) % mod)) % mod;
}

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

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;

    if (n % 2 == 0) {
      if (a[tmp] == 2)
        check[tmp] = true;
      else
        check[tmp] = false;
    } else {
      if (tmp == 0) {
        if (a[tmp] == 1)
          check[tmp] = true;
        else
          check[tmp] = false;
      } else {
        if (a[tmp] == 2)
          check[tmp] = true;
        else
          check[tmp] = false;
      }
    }
  }

  bool ans = true;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0)
        ans = !check[i];
      else
        ans = check[i];

      if (!ans)
        break;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 1)
        ans = !check[i];
      else
        ans = check[i];

      if (!ans)
        break;
    }
  }

  if (!ans) {
    p(0)
  } else {
    p(get2(n / 2))
  }
}

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

const long long int mod = 1e9 + 7;
const long long int limit = 1e5;

int a[limit];
bool check[limit];

#define p(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

long long int get2(long long int n) {
  if (n == 1)
    return 2;
  else
    return (2 * (get2(n - 1) % mod)) % mod;
}

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

  if (n == 1) {
    int tmp;
    cin >> tmp;
    p((tmp == 0 ? 1 : 0)) return 0;
  }

  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a[tmp]++;

    if (n % 2 == 0) {
      if (a[tmp] == 2)
        check[tmp] = true;
      else
        check[tmp] = false;
    } else {
      if (tmp == 0) {
        if (a[tmp] == 1)
          check[tmp] = true;
        else
          check[tmp] = false;
      } else {
        if (a[tmp] == 2)
          check[tmp] = true;
        else
          check[tmp] = false;
      }
    }
  }

  bool ans = true;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0)
        ans = !check[i];
      else
        ans = check[i];

      if (!ans)
        break;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 1)
        ans = !check[i];
      else
        ans = check[i];

      if (!ans)
        break;
    }
  }

  if (!ans) {
    p(0)
  } else {
    p(get2(n / 2))
  }
}
Problem p03848 (C++)

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

using namespace std;

const int MAX = 10000;

typedef long long ll;

int cnt[MAX], n;

bool check(int id) {
  while (id <= n - 1) {
    if (cnt[id] != 2)
      return false;
    id = id + 2;
  }
  return true;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  bool pos;
  if (n % 2 == 0) {
    pos = check(1);
  } else {
    if (cnt[0] != 1)
      pos = false;
    else
      pos = check(2);
  }
  if (pos) {
    ll ans = 1;
    for (int i = 0; i < n / 2; i++) {
      ans = (ans * 2) % 1000000007;
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}

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

using namespace std;

const int MAX = 100000;

typedef long long ll;

int cnt[MAX], n;

bool check(int id) {
  while (id <= n - 1) {
    if (cnt[id] != 2)
      return false;
    id = id + 2;
  }
  return true;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  bool pos;
  if (n % 2 == 0) {
    pos = check(1);
  } else {
    if (cnt[0] != 1)
      pos = false;
    else
      pos = check(2);
  }
  if (pos) {
    ll ans = 1;
    for (int i = 0; i < n / 2; i++) {
      ans = (ans * 2) % 1000000007;
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
}
Problem p03848 (C++)

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
const lli mod = 1'000'000'007;

lli pw(lli n) {
  if (n == 1)
    return 2;
  if (n % 2) {
    return (2 * pw(n - 1)) % mod;
  } else {
    lli t = pw(n / 2);
    return (t * t) % mod;
  }
}

int main() {
  lli N;
  cin >> N;
  vector<int> A(N, 0);
  REP(i, 0, N) {
    int t;
    cin >> t;
    A[t]++;
  }
  lli ans = pw(N / 2);
  bool ok = true;
  if (N % 2)
    A[0]++;
  for (int i = !(N % 2); i < N; i += 2) {
    if (A[i] != 2)
      ok = false;
  }
  cout << ok * ans << endl;
  return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
const lli mod = 1'000'000'007;

lli pw(lli n) {
  if (n == 0)
    return 1;
  if (n == 1)
    return 2;
  if (n % 2) {
    return (2 * pw(n - 1)) % mod;
  } else {
    lli t = pw(n / 2);
    return (t * t) % mod;
  }
}

int main() {
  lli N;
  cin >> N;
  vector<int> A(N, 0);
  REP(i, 0, N) {
    int t;
    cin >> t;
    A[t]++;
  }
  lli ans = pw(N / 2);
  bool ok = true;
  if (N % 2)
    A[0]++;
  for (int i = !(N % 2); i < N; i += 2) {
    if (A[i] != 2)
      ok = false;
  }
  cout << ok * ans << endl;
  return 0;
}