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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll kai[100002];
ll gyaku[100002];
ll modpow(ll n, ll a) {
  ll ret = 1;
  ll nn = n;
  while (a > 0) {
    if (a & 1) {
      ret *= nn;
      ret %= MOD;
    }
    nn = nn * nn;
    nn %= MOD;
    a >>= 1;
  }
  return ret;
}

ll combi(int a, int b) {
  ll ret = kai[a] * gyaku[b];
  ret %= MOD;
  ret *= gyaku[a - b];
  ret %= MOD;
  return ret;
}

int main() {
  int n;
  int l, r, kabu;
  int cnt[100001];
  fill(cnt, cnt + 100001, 0);
  int a[100000];
  cin >> n;
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    if (cnt[a[i]] == 2) {
      kabu = a[i];
      r = n - i;
    }
  }
  for (int i = 0; i < n + 1; i++) {
    if (a[i] == kabu) {
      l = i;
      break;
    }
  }
  kai[0] = 1;
  gyaku[0] = modpow(kai[0], MOD - 2);
  for (ll i = 1; i < 100002; i++) {
    kai[i] = (kai[i - 1] * i + MOD) % MOD;
    gyaku[i] = modpow(kai[i], MOD - 2);
  }
  cout << n << endl;
  ll tmp = 0;
  for (int k = 2; k <= n + 1; k++) {
    tmp = combi(n + 1, k);
    for (int i = 0; i <= l; i++) {
      if (k - 1 - i > r)
        continue;
      if (k - 1 - i < 0)
        break;
      // cerr<<k<<" "<<i<<" "<<k-1-i<<" "<<combi(l,i)<<"
      // "<<combi(r,k-1-i)<<endl;
      tmp -= combi(l, i) * combi(r, k - 1 - i);
      tmp %= MOD;
    }
    if (tmp < 0)
      tmp += MOD;
    cout << tmp << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll kai[100002];
ll gyaku[100002];
ll modpow(ll n, ll a) {
  ll ret = 1;
  ll nn = n;
  while (a > 0) {
    if (a & 1) {
      ret *= nn;
      ret %= MOD;
    }
    nn = nn * nn;
    nn %= MOD;
    a >>= 1;
  }
  return ret;
}

ll combi(int a, int b) {
  ll ret = kai[a] * gyaku[b];
  ret %= MOD;
  ret *= gyaku[a - b];
  ret %= MOD;
  return ret;
}

int main() {
  int n;
  int l, r, kabu;
  int cnt[100001];
  fill(cnt, cnt + 100001, 0);
  int a[100000];
  cin >> n;
  for (int i = 0; i < n + 1; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    if (cnt[a[i]] == 2) {
      kabu = a[i];
      r = n - i;
    }
  }
  for (int i = 0; i < n + 1; i++) {
    if (a[i] == kabu) {
      l = i;
      break;
    }
  }
  kai[0] = 1;
  gyaku[0] = modpow(kai[0], MOD - 2);
  for (ll i = 1; i < 100002; i++) {
    kai[i] = (kai[i - 1] * i + MOD) % MOD;
    gyaku[i] = modpow(kai[i], MOD - 2);
  }
  cout << n << endl;
  ll tmp = 0;
  for (int k = 2; k <= n + 1; k++) {
    tmp = combi(n + 1, k);
    if (l + r >= k - 1)
      tmp -= combi(l + r, k - 1);
    tmp %= MOD;
    if (tmp < 0)
      tmp += MOD;
    cout << tmp << endl;
  }
  return 0;
}
Problem p03674 (C++)

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

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint pow(lint x, lint e) {
  if (e == 1)
    return x % MOD;
  if (e == 0)
    return 1;
  return pow(x * x % MOD, e / 2) * (e % 2 == 0 ? 1 : x) % MOD;
}
lint inv(lint i) { return pow(i, MOD - 2); }
lint fact[100002], factinv[100002];
lint C(lint n, lint r) {
  return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
}

int main() {
  lint n, a;
  bool c[100002];
  for (lint i = 1; i <= n; i++)
    c[i] = false;
  lint p[100002];
  lint x, y;

  cin >> n;
  for (lint i = 0; i <= n; i++) {
    cin >> a;
    if (c[a]) {
      x = p[a];
      y = i;
    }
    c[a] = true;
    p[a] = i;
  }

  fact[0] = 1;
  for (lint i = 1; i <= n + 1; i++)
    fact[i] = i * fact[i - 1] % MOD;
  for (lint i = 0; i <= n + 1; i++)
    factinv[i] = inv(fact[i]);

  for (lint i = 1; i <= n + 1; i++) {
    lint ans;
    ans = C(n + 1, i);
    ans += MOD - C(n - (y - x), i - 1);
    cout << (ans % MOD) << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint pow(lint x, lint e) {
  if (e == 1)
    return x % MOD;
  if (e == 0)
    return 1;
  return pow(x * x % MOD, e / 2) * (e % 2 == 0 ? 1 : x) % MOD;
}
lint inv(lint i) { return pow(i, MOD - 2); }
lint fact[100002], factinv[100002];
lint C(lint n, lint r) {
  return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
}

int main() {
  lint n, a;
  bool c[100002];
  for (lint i = 1; i <= n; i++)
    c[i] = false;
  lint p[100002];
  lint x, y;

  cin >> n;
  for (lint i = 0; i <= n; i++) {
    cin >> a;
    if (c[a]) {
      x = p[a];
      y = i;
    }
    c[a] = true;
    p[a] = i;
  }

  fact[0] = 1;
  for (lint i = 1; i <= n + 1; i++)
    fact[i] = i * fact[i - 1] % MOD;
  for (lint i = 0; i <= n + 1; i++)
    factinv[i] = inv(fact[i]);

  for (lint i = 1; i <= n + 1; i++) {
    lint ans;
    ans = C(n + 1, i);
    if (i - 1 <= n - (y - x))
      ans += MOD - C(n - (y - x), i - 1);
    cout << (ans % MOD) << endl;
  }

  return 0;
}
Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 201000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n;
  cin >> n;
  vector<ll> a(n), cnt(n, 0);
  // 2つある数字をs, a[i]=sとなるiをleft,right
  ll s, left, right;
  REP(i, n + 1) {
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
    if (cnt[a[i]] == 2) {
      s = a[i];
      right = i;
    }
  }
  REP(i, n) {
    if (a[i] == s) {
      left = i;
      break;
    }
  }
  FOR(k, 1, n + 2) {
    cout << (ll)(MOD + COM(n + 1, k) - COM(left + n - right, k - 1)) % MOD
         << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 201000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll n;
  cin >> n;
  vector<ll> a(n + 1), cnt(n, 0);
  // 2つある数字をs, a[i]=sとなるiをleft,right
  ll s, left, right;
  REP(i, n + 1) {
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
    if (cnt[a[i]] == 2) {
      s = a[i];
      right = i;
    }
  }
  REP(i, n) {
    if (a[i] == s) {
      left = i;
      break;
    }
  }
  FOR(k, 1, n + 2) {
    cout << (ll)(MOD + COM(n + 1, k) - COM(left + n - right, k - 1)) % MOD
         << endl;
  }
}
Problem p03674 (C++)

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

#define int long long
const int mod = 1e9 + 7;

class FermatCombination {
private:
  vector<int> fac, inv;

  int Pow(int x, int n) {
    int ans = 1;
    while (n > 0) {
      if (n & 1)
        ans = (ans * x) % mod;
      x = (x * x) % mod;
      n >>= 1;
    }
    return ans;
  }
  void Factrial(int n) {
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= n; i++) {
      fac[i] = (fac[i - 1] * i) % mod;
      inv[i] = Pow(fac[i], mod - 2);
    }
  }

public:
  void init(int n) { // nCk
    fac.resize(n + 1);
    inv.resize(n + 1);
    Factrial(n);
  }
  int combine(int n, int k) {
    int tmp = (fac[n] * inv[k]) % mod;
    return (tmp * inv[n - k]) % mod;
  }
};

FermatCombination C;
int a[100002], b[100002];
const int MAX_N = 100010;

int comb(int x, int y) {
  if (x < y)
    return 0;
  if (y == 0)
    return 1;
  return C.combine(x, y);
}

signed main() {
  int n, l1, l2;
  int hash[MAX_N] = {};
  fill(hash, hash + MAX_N, -1);
  scanf("%lld", &n);
  for (int i = 0; i < n + 1; i++) {
    int a;
    scanf("%lld", &a);
    if (hash[a] != -1) {
      l1 = hash[a];
      l2 = i;
    }
    hash[a] = i;
  }

  for (int k = 1; k <= n + 1; k++) {
    int ans = comb(n + 1, k) - comb(n + l1 - l2, k - 1) + mod;
    cout << ans % mod << "\n";
  }

  return 0;
}


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

#define int long long
const int mod = 1e9 + 7;

class FermatCombination {
private:
  vector<int> fac, inv;

  int Pow(int x, int n) {
    int ans = 1;
    while (n > 0) {
      if (n & 1)
        ans = (ans * x) % mod;
      x = (x * x) % mod;
      n >>= 1;
    }
    return ans;
  }
  void Factrial(int n) {
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= n; i++) {
      fac[i] = (fac[i - 1] * i) % mod;
      inv[i] = Pow(fac[i], mod - 2);
    }
  }

public:
  void init(int n) { // nCk
    fac.resize(n + 1);
    inv.resize(n + 1);
    Factrial(n);
  }
  int combine(int n, int k) {
    int tmp = (fac[n] * inv[k]) % mod;
    return (tmp * inv[n - k]) % mod;
  }
};

FermatCombination C;
int a[100002], b[100002];
const int MAX_N = 100010;

int comb(int x, int y) {
  if (x < y)
    return 0;
  if (y == 0)
    return 1;
  return C.combine(x, y);
}

signed main() {
  int n, l1, l2;
  int hash[MAX_N] = {};
  fill(hash, hash + MAX_N, -1);
  scanf("%lld", &n);
  for (int i = 0; i < n + 1; i++) {
    int a;
    scanf("%lld", &a);
    if (hash[a] != -1) {
      l1 = hash[a];
      l2 = i;
    }
    hash[a] = i;
  }

  C.init(n + 1);
  for (int k = 1; k <= n + 1; k++) {
    int ans = comb(n + 1, k) - comb(n + l1 - l2, k - 1) + mod;
    cout << ans % mod << "\n";
  }

  return 0;
}
Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

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

ll Inverse(ll a) { return Pow(a, MOD - 2); }

void Facto_Ini(vector<ll> &k) {
  ll a = 1, i;
  for (i = 1; i < k.size(); i++) {
    a *= i;
    a %= MOD;
    k[i] = a;
  }
  return;
}

ll Combi(int n, int a, vector<ll> &k) {
  a = min(n - a, a);
  if (a < 0)
    return 0ll;
  if (a == 0)
    return 1ll;
  ll ans = k[n] * Inverse(k[a]);
  ans %= MOD;
  ans *= Inverse(k[n - a]);
  ans %= MOD;
  return ans;
}

int main(void) {
  int num, i, l, a;
  ll ans;
  cin >> num;
  num++;
  vector<int> p(num, 0);
  vector<ll> k(num + 1, 0);
  for (i = 1; i < num; i++) {
    cin >> a;
    if (!p[a])
      p[a] = i;
    else {
      l = p[a];
      l += num - i - 1;
      break;
    }
  }
  Facto_Ini(k);
  for (i = 1; i <= num; i++) {
    ans = Combi(num, i, k) - Combi(l, i - 1, k);
    if (ans < 0)
      ans += MOD;
    cout << ans << "\n";
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

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

ll Inverse(ll a) { return Pow(a, MOD - 2); }

void Facto_Ini(vector<ll> &k) {
  ll a = 1, i;
  for (i = 1; i < k.size(); i++) {
    a *= i;
    a %= MOD;
    k[i] = a;
  }
  return;
}

ll Combi(int n, int a, vector<ll> &k) {
  a = min(n - a, a);
  if (a < 0)
    return 0ll;
  if (a == 0)
    return 1ll;
  ll ans = k[n] * Inverse(k[a]);
  ans %= MOD;
  ans *= Inverse(k[n - a]);
  ans %= MOD;
  return ans;
}

int main(void) {
  int num, i, l, a;
  ll ans;
  cin >> num;
  num++;
  vector<int> p(num, 0);
  vector<ll> k(num + 1, 0);
  for (i = 1; i <= num; i++) {
    cin >> a;
    if (!p[a])
      p[a] = i;
    else {
      l = p[a];
      l += num - i - 1;
      break;
    }
  }
  Facto_Ini(k);
  for (i = 1; i <= num; i++) {
    ans = Combi(num, i, k) - Combi(l, i - 1, k);
    if (ans < 0)
      ans += MOD;
    cout << ans << "\n";
  }
  return 0;
}
Problem p03674 (C++)

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

using namespace std;
typedef long long ll;
const int MAXN = 100010;
const int MOD = 1e9 + 7;
int n_;
int a[MAXN];
bool exist[MAXN];
ll dp[MAXN];

void init() {
  dp[0] = dp[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    dp[i] = i * dp[i - 1] % MOD;
  }
}

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

ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }

ll nCr(ll n, ll r) {
  return (dp[n] * mod_inv(dp[r]) % MOD) * mod_inv(dp[n - r]) % MOD;
}

void solve() {
  init();
  int first = 0, second = 0;
  for (int i = 0; i <= n_; i++) {
    if (exist[a[i]]) {
      second = i;
      break;
    }
    exist[a[i]] = true;
  }
  for (int i = 0; i <= n_; i++) {
    if (a[i] == a[second]) {
      first = i;
      break;
    }
  }
  for (int i = 1; i <= n_ + 1; i++) {
    ll ans = (nCr(n_ + 1, i) - nCr(first + n_ - second, i - 1) + MOD) % MOD;
    cout << ans << endl;
  }
}

int main() {
  cin >> n_;
  for (int i = 0; i <= n_; i++) {
    cin >> a[i];
  }
  solve();
}


Fixed submission:
// review
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 100010;
const int MOD = 1e9 + 7;
int n_;
int a[MAXN];
bool exist[MAXN];
ll dp[MAXN];

void init() {
  dp[0] = dp[1] = 1;
  for (int i = 2; i < MAXN; i++) {
    dp[i] = i * dp[i - 1] % MOD;
  }
}

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

ll mod_inv(ll x) { return mod_pow(x, MOD - 2) % MOD; }

ll nCr(ll n, ll r) {
  if (n < r) {
    return 0;
  }
  return (dp[n] * mod_inv(dp[r]) % MOD) * mod_inv(dp[n - r]) % MOD;
}

void solve() {
  init();
  int first = 0, second = 0;
  for (int i = 0; i <= n_; i++) {
    if (exist[a[i]]) {
      second = i;
      break;
    }
    exist[a[i]] = true;
  }
  for (int i = 0; i <= n_; i++) {
    if (a[i] == a[second]) {
      first = i;
      break;
    }
  }
  for (int i = 1; i <= n_ + 1; i++) {
    ll ans = (nCr(n_ + 1, i) - nCr(first + n_ - second, i - 1) + MOD) % MOD;
    cout << ans << endl;
  }
}

int main() {
  cin >> n_;
  for (int i = 0; i <= n_; i++) {
    cin >> a[i];
  }
  solve();
}
Problem p03674 (C++)

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

typedef long long ll;
typedef unsigned long long ull;

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  int n, d, l = -1, r;
  cin >> n;
  vector<ll> f(n + 2, 1);
  ll MOD = 1e9 + 7;
  rep(i, n + 1) f[i + 1] = (f[i] * (i + 1)) % MOD;
  vector<int> a(n + 1), c(n, 0);
  rep(i, n + 1) {
    cin >> a[i];
    c[a[i] - 1]++;
    if (c[a[i] - 1] == 2)
      d = a[i];
  }
  rep(i, n + 1) {
    if (a[i] == d) {
      if (l == -1)
        l = i;
      else
        r = i;
    }
  }
  int m = n + 1 - (r - l + 1);
  // cout << "m=" << m << "\n";
  rep(i, n + 1) {
    ll ans = f[n + 1] * mod_pow(f[i + 1], MOD - 2, MOD);
    ans %= MOD;
    ans *= mod_pow(f[n - i], MOD - 2, MOD);
    ans %= MOD;
    ll x = f[m] * mod_pow(f[i], MOD - 2, MOD);
    x %= MOD;
    x *= mod_pow(f[m - i], MOD - 2, MOD);
    // cout << "ans=" << ans << " x=" << x << "\n";
    cout << (ans - x + MOD) % MOD << "\n";
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  int n, d, l = -1, r;
  cin >> n;
  vector<ll> f(n + 2, 1);
  ll MOD = 1e9 + 7;
  rep(i, n + 1) f[i + 1] = (f[i] * (i + 1)) % MOD;
  vector<int> a(n + 1), c(n, 0);
  rep(i, n + 1) {
    cin >> a[i];
    c[a[i] - 1]++;
    if (c[a[i] - 1] == 2)
      d = a[i];
  }
  rep(i, n + 1) {
    if (a[i] == d) {
      if (l == -1)
        l = i;
      else
        r = i;
    }
  }
  int m = n + 1 - (r - l + 1);
  // cout << "m=" << m << "\n";
  rep(i, n + 1) {
    ll ans = f[n + 1] * mod_pow(f[i + 1], MOD - 2, MOD);
    ans %= MOD;
    ans *= mod_pow(f[n - i], MOD - 2, MOD);
    ans %= MOD;
    ll x;
    if (i > m)
      x = 0;
    else {
      x = f[m] * mod_pow(f[i], MOD - 2, MOD);
      x %= MOD;
      x *= mod_pow(f[m - i], MOD - 2, MOD);
      x %= MOD;
    }
    // cout << "ans=" << ans << " x=" << x << "\n";
    cout << (ans - x + MOD) % MOD << "\n";
  }
}
Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const int M = 1e9 + 7;
const int N = 1e5 + 5;
using namespace std;
long long f[N], fi[N];
int powr(int a, int b) {
  long long y = a, x = 1;
  while (b > 0) {
    if (b & 1)
      x = (x * y) % M;
    y = (y * y) % M;
    b = b / 2;
  }
  return x % M;
}
int mod_inv(int n) { return powr(n, M - 2); }
int c(int n, int r) { return ((f[n] * fi[r]) % M * fi[n - r]) % M; }
int main() {
  map<int, int> m;
  int n, tp;
  cin >> n;
  n++;
  int a[n + 3];
  long long ans[n + 3];
  f[0] = fi[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = (f[i - 1] * i) % M;
    fi[i] = (mod_inv(i) * fi[i - 1]) % M;
  }
  for (int i = 1; i <= n; i++) {
    if (m[a[i]] == 0)
      m[a[i]] = i;
    else {
      tp = i - m[a[i]] + 1;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    int rs = c(n, i);
    ans[i] = rs - c(n - tp, i - 1);
    if (ans[i] < 0)
      ans[i] = (ans[i] + M) % M;
    cout << ans[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
const int M = 1e9 + 7;
const int N = 1e5 + 5;
using namespace std;
long long f[N], fi[N];
int powr(int a, int b) {
  long long y = a, x = 1;
  while (b > 0) {
    if (b & 1)
      x = (x * y) % M;
    y = (y * y) % M;
    b = b / 2;
  }
  return x % M;
}
int mod_inv(int n) { return powr(n, M - 2); }
int c(int n, int r) {
  if (r > n)
    return 0;
  return ((f[n] * fi[r]) % M * fi[n - r]) % M;
}
int main() {
  map<int, int> m;
  int n, tp;
  cin >> n;
  n++;
  int a[n + 3];
  long long ans[n + 3];
  f[0] = fi[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = (f[i - 1] * i) % M;
    fi[i] = (mod_inv(i) * fi[i - 1]) % M;
  }
  for (int i = 1; i <= n; i++) {
    if (m[a[i]] == 0)
      m[a[i]] = i;
    else {
      tp = i - m[a[i]] + 1;
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    int rs = c(n, i);
    ans[i] = rs - c(n - tp, i - 1);
    if (ans[i] < 0)
      ans[i] = (ans[i] + M) % M;
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p03674 (C++)

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

const int MAX = 101000;
ll fact[MAX], fact_inv[MAX];

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

ll comb(ll n, ll r) {
  return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

bool exist[MAX];

int main() {
  const int bound = 100500;
  fact[0] = 1;
  for (int i = 0; i < bound; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
  fact_inv[bound] = power(fact[bound], MOD - 2);
  for (int i = bound - 1; i >= 0; --i) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
  }
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int dup = 0;
  for (int i = 0; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    if (exist[tmp])
      dup = tmp;
    exist[tmp] = true;
    a[i] = tmp;
  }
  ll x = -1, y = -1;
  for (int i = 0; i <= n; ++i) {
    if (a[i] == dup) {
      if (x == -1)
        x = i;
      else
        y = n - i;
    }
  }
  // cout << x << " " << y << endl;
  for (ll i = 1; i <= n + 1; ++i) {
    cout << (comb(n + 1, i) + comb(x + y, i) + MOD - comb(x + y + 1, i)) % MOD
         << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int MAX = 101000;
ll fact[MAX], fact_inv[MAX];

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

ll comb(ll n, ll r) {
  return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

bool exist[MAX];

int main() {
  const int bound = 100500;
  fact[0] = 1;
  for (int i = 0; i < bound; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
  fact_inv[bound] = power(fact[bound], MOD - 2);
  for (int i = bound - 1; i >= 0; --i) {
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
  }
  int n;
  cin >> n;
  vector<int> a(n + 1);
  int dup = 0;
  for (int i = 0; i <= n; ++i) {
    int tmp;
    cin >> tmp;
    if (exist[tmp])
      dup = tmp;
    exist[tmp] = true;
    a[i] = tmp;
  }
  ll x = -1, y = -1;
  for (int i = 0; i <= n; ++i) {
    if (a[i] == dup) {
      if (x == -1)
        x = i;
      else
        y = n - i;
    }
  }
  // cout << x << " " << y << endl;
  for (ll i = 1; i <= n + 1; ++i) {
    if (x + y + 1 < i) {
      cout << comb(n + 1, i) % MOD << endl;
    } else {
      cout << (comb(n + 1, i) + comb(x + y, i) + MOD - comb(x + y + 1, i)) % MOD
           << endl;
    }
  }
  return 0;
}
Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
typedef pair<int, int> pint;
typedef long long ll;
const int inf = 1 << 30;
const ll longinf = 1LL << 60;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int mod = 1000000007;

ll fact[100005];

ll calc(ll n, ll k) {
  if (k == 0)
    return 1;
  ll m = n * n % mod;
  if (k % 2)
    return n * calc(m, k / 2) % mod;
  else
    return calc(m, k / 2) % mod;
}

ll comb(ll n, ll k) {
  ll ret = fact[n];
  ret = ret * calc(fact[k], mod - 2) % mod;
  ret = ret * calc(fact[n - k], mod - 2) % mod;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  int a[n];
  rep(i, n) a[i + 1] = 0;
  ll left, right;
  rep(i, n) {
    int x;
    cin >> x;
    if (a[x] == 0)
      a[x] = i + 1;
    else {
      left = a[x];
      right = i + 1;
      break;
    }
  }
  fact[0] = 1;
  rep(i, n + 1) fact[i + 1] = (i + 1) * fact[i] % mod;
  rep(i, n + 1) {
    if (right - left + i <= n) {
      ll ans = comb(n + 1, i + 1) - comb(n - right + left, i);
      if (ans < 0)
        ans += mod;
      cout << ans << endl;
    } else
      cout << comb(n + 1, i + 1) << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
typedef pair<int, int> pint;
typedef long long ll;
const int inf = 1 << 30;
const ll longinf = 1LL << 60;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int mod = 1000000007;

ll fact[100005];

ll calc(ll n, ll k) {
  if (k == 0)
    return 1;
  ll m = n * n % mod;
  if (k % 2)
    return n * calc(m, k / 2) % mod;
  else
    return calc(m, k / 2) % mod;
}

ll comb(ll n, ll k) {
  ll ret = fact[n];
  ret = ret * calc(fact[k], mod - 2) % mod;
  ret = ret * calc(fact[n - k], mod - 2) % mod;
  return ret;
}

int main() {
  ll n;
  cin >> n;
  int a[n];
  rep(i, n) a[i + 1] = 0;
  ll left, right;
  rep(i, n + 1) {
    int x;
    cin >> x;
    if (a[x] == 0)
      a[x] = i + 1;
    else {
      left = a[x];
      right = i + 1;
      break;
    }
  }
  fact[0] = 1;
  rep(i, n + 1) fact[i + 1] = (i + 1) * fact[i] % mod;
  rep(i, n + 1) {
    if (right - left + i <= n) {
      ll ans = comb(n + 1, i + 1) - comb(n - right + left, i);
      if (ans < 0)
        ans += mod;
      cout << ans << endl;
    } else
      cout << comb(n + 1, i + 1) << endl;
  }
  return 0;
}
Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n, a[N];
ll fac[N];
int vis[N], d;
ll ksm(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ans;
}
ll C(int n, int k) {
  return fac[n] * ksm(fac[k] * fac[n - k] % mod, mod - 2) % mod;
}
int main() {
  scanf("%d", &n);
  fac[0] = 1;
  for (int i = 1; i <= n + 1; i++) {
    scanf("%d", &a[i]);
    if (vis[a[i]])
      d = (i - vis[a[i]]);
    vis[a[i]] = i;
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= n + 1; i++) {
    printf("%lld\n", ((C(n + 1, i) - C(n - d, i - 1)) % mod + mod) % mod);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5, M = 2e4 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
#define mst(a, b) memset(a, b, sizeof a)
#define lx x << 1
#define rx x << 1 | 1
#define reg register
#define PII pair<int, int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n, a[N];
ll fac[N];
int vis[N], d;
ll ksm(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ans;
}
ll C(int n, int k) {
  if (n < k)
    return 0;
  return fac[n] * ksm(fac[k] * fac[n - k] % mod, mod - 2) % mod;
}
int main() {
  scanf("%d", &n);
  fac[0] = 1;
  for (int i = 1; i <= n + 1; i++) {
    scanf("%d", &a[i]);
    if (vis[a[i]])
      d = (i - vis[a[i]]);
    vis[a[i]] = i;
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= n + 1; i++) {
    printf("%lld\n", ((C(n + 1, i) - C(n - d, i - 1)) % mod + mod) % mod);
  }
  return 0;
}
Problem p03674 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using Int = long long;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
template <typename Container> void P(const Container &c) {
  for (const auto &x : c)
    cout << x << ' ';
  cout << '\n';
}
const int MOD = 1000000007;
int ADD(int x, int y) { return (x + y) % MOD; }
int MUL(int x, int y) { return ((Int)x * y) % MOD; }
int FACT(int x) { return x == 0 ? 1 : MUL(x, FACT(x - 1)); }
int POW(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = MUL(res, x);
    x = MUL(x, x);
    y >>= 1;
  }
  return res;
}
int INV(int x) { return POW(x, MOD - 2); }
int COMB(int n, int k) { return MUL(FACT(n), INV(MUL(FACT(n - k), FACT(k)))); }
int main() {
  int N;
  cin >> N;
  vector<int> pos(N + 1, -1);
  int dupidx, dupnum;
  REP(i, N + 1) {
    int a;
    cin >> a;
    a--;
    if (pos[a] == -1)
      pos[a] = i;
    else
      dupidx = i, dupnum = a;
  }
  int M = dupidx - pos[dupnum] + 1;
  for (int k = 1; k <= N + 1; k++) {
    int remove = N + 1 - M < k - 1 ? 0 : COMB(N + 1 - M, k - 1);
    cout << ADD(COMB(N + 1, k), MOD - remove) << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using Int = long long;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
template <typename Container> void P(const Container &c) {
  for (const auto &x : c)
    cout << x << ' ';
  cout << '\n';
}
const int MOD = 1000000007;
int ADD(int x, int y) { return (x + y) % MOD; }
int MUL(int x, int y) { return ((Int)x * y) % MOD; }
int FACT(int x) {
  if (x == 0)
    return 1;
  static int memo[100002];
  static bool init = false;
  if (!init) {
    REP(i, 100002) memo[i] = -1;
    init = true;
  }
  if (memo[x] != -1)
    return memo[x];
  else
    return memo[x] = MUL(x, FACT(x - 1));
}
int POW(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1)
      res = MUL(res, x);
    x = MUL(x, x);
    y >>= 1;
  }
  return res;
}
int INV(int x) { return POW(x, MOD - 2); }
int COMB(int n, int k) { return MUL(FACT(n), INV(MUL(FACT(n - k), FACT(k)))); }
int main() {
  int N;
  cin >> N;
  vector<int> pos(N + 1, -1);
  int dupidx, dupnum;
  REP(i, N + 1) {
    int a;
    cin >> a;
    a--;
    if (pos[a] == -1)
      pos[a] = i;
    else
      dupidx = i, dupnum = a;
  }
  int M = dupidx - pos[dupnum] + 1;
  for (int k = 1; k <= N + 1; k++) {
    int remove = N + 1 - M < k - 1 ? 0 : COMB(N + 1 - M, k - 1);
    cout << ADD(COMB(N + 1, k), MOD - remove) << endl;
  }
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <deque>
#include <iostream>
#define LL long long
using namespace std;
deque<int> b;
deque<int>::iterator it;
int a[100010], c[100010];
int main() {
  int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    c[i] = (n - i) % 2;
    cin >> a[i];
  }

  for (i = 1; i <= n; i++) {
    if (c[i])
      b.push_back(a[i]);
    else
      b.push_front(a[i]);
  }
  for (it = b.begin(); it != b.end(); it++)
    cout << *it << ' ';
  cout << endl;
}


Fixed submission:
#include <deque>
#include <iostream>
#define LL long long
using namespace std;
deque<int> b;
deque<int>::iterator it;
int a[200010], c[200010];
int main() {
  int n, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    c[i] = (n - i) % 2;
    cin >> a[i];
  }

  for (i = 1; i <= n; i++) {
    if (c[i])
      b.push_back(a[i]);
    else
      b.push_front(a[i]);
  }
  for (it = b.begin(); it != b.end(); it++)
    cout << *it << ' ';
  cout << endl;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <queue>
#include <stdio.h>

using namespace std;

const int NN = 120000;
int n;
int a[NN];
deque<int> q;
int ans[NN];
void work() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i % 2 == 0)
      q.push_back(a[i]);
    else
      q.push_front(a[i]);
  }
  if (n % 2 == 1) {
    for (i = 1; i <= n; i++) {
      ans[i] = q.front();
      q.pop_front();
    }
  } else {
    for (i = 1; i <= n; i++) {
      ans[i] = q.back();
      q.pop_back();
    }
  }
  for (i = 1; i <= n; i++)
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
}
int main() {
  work();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <queue>
#include <stdio.h>

using namespace std;

const int NN = 220000;
int n;
int a[NN];
deque<int> q;
int ans[NN];
void work() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i % 2 == 0)
      q.push_back(a[i]);
    else
      q.push_front(a[i]);
  }
  if (n % 2 == 1) {
    for (i = 1; i <= n; i++) {
      ans[i] = q.front();
      q.pop_front();
    }
  } else {
    for (i = 1; i <= n; i++) {
      ans[i] = q.back();
      q.pop_back();
    }
  }
  for (i = 1; i <= n; i++)
    printf("%d%c", ans[i], i == n ? '\n' : ' ');
}
int main() {
  work();
  return 0;
}
Problem p03675 (C++)

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

using namespace std;

int a[100000 + 5];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    // n-1 1 -> 0
    // n-2 2 -> n-1
    // n-3 3 -> 1
    // n-4 4 -> n-2
    int idx = n - i;
    if (idx % 2 == 1)
      idx /= 2;
    else
      idx = n - idx / 2;
    cin >> a[idx];
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << ' ';
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int a[200000 + 5];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    // n-1 1 -> 0
    // n-2 2 -> n-1
    // n-3 3 -> 1
    // n-4 4 -> n-2
    int idx = n - i;
    if (idx % 2 == 1)
      idx /= 2;
    else
      idx = n - idx / 2;
    cin >> a[idx];
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i] << ' ';
  }
  cout << endl;
  return 0;
}
Problem p03675 (C++)

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

using namespace std;

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fileio freopen("in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout << n1 << endl
ll n, a[100005], b[100005];
int main() {
  slld(n);
  ll x = n / 2 + 1;
  for (int i = 1; i <= n; i++) {
    slld(a[i]);
    if (i % 2 != n % 2)
      b[x + i / 2] = a[i];
    else
      b[x - i / 2] = a[i];
  }
  for (int i = 1; i <= n; i++)
    pss("%lld ", b[i]);
  pss("\n");
  return 0;
}

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

using namespace std;

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fileio freopen("in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define pd(x) printf("%d\n", x)
#define plld(x) printf("%lld\n", x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout << n1 << endl
ll n, a[200005], b[200005];
int main() {
  slld(n);
  ll x = n / 2 + 1;
  for (int i = 1; i <= n; i++) {
    slld(a[i]);
    if (i % 2 != n % 2)
      b[x + i / 2] = a[i];
    else
      b[x - i / 2] = a[i];
  }
  for (int i = 1; i <= n; i++)
    pss("%lld ", b[i]);
  pss("\n");
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = 1e9 + 1;
int a[100005];
vector<int> ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int i = n;
  while (i >= 2) {
    ans.push_back(a[i]);
    i -= 2;
  }
  ans.push_back(a[1]);
  if (n % 2 == 0)
    i = 3;
  else
    i = 2;
  while (i <= n) {
    ans.push_back(a[i]);
    i += 2;
  }
  for (int j = 0; j < ans.size(); j++) {
    cout << ans[j] << " ";
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int INF = 1e9 + 1;
int a[200005];
vector<int> ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int i = n;
  while (i >= 2) {
    ans.push_back(a[i]);
    i -= 2;
  }
  ans.push_back(a[1]);
  if (n % 2 == 0)
    i = 3;
  else
    i = 2;
  while (i <= n) {
    ans.push_back(a[i]);
    i += 2;
  }
  for (int j = 0; j < ans.size(); j++) {
    cout << ans[j] << " ";
  }
  cout << endl;
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 100005;

int n, x;
int a[N], b[N];

int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    x = (n - i + 2) / 2;
    if (n - i + 1 & 1)
      b[x] = a[i];
    else
      b[x + i] = a[i];
  }
  for (i = 1; i <= n; i++)
    printf("%d ", b[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

const int N = 200005;

int n, x;
int a[N], b[N];

int main() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (i = 1; i <= n; i++) {
    x = (n - i + 2) / 2;
    if (n - i + 1 & 1)
      b[x] = a[i];
    else
      b[x + i] = a[i];
  }
  for (i = 1; i <= n; i++)
    printf("%d ", b[i]);
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define dbgi(x) cout << #x << " = " << (x) << "\n";
#define dbgvi(x)                                                               \
  cout << #x << " = ";                                                         \
  for (int i = 0; i < (x.size()); ++i)                                         \
    cout << x[i] << " ";
#define mrk() cout << "HERE\n"
#define vi vector<int>
#define vs vector<string>
#define vii vector<vi>
#define viii vector<vii>
#define viiii vector<viii>
#define pii pair<int, int>
#define vpii vector<pii>
#define foru(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, b, a) for (int i = b; i > a; --i)
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ld long double
using namespace std;

signed main() {
  int n;
  cin >> n;
  vi a(n);
  foru(i, 1, n + 1) cin >> a[i];
  vi odd;
  vi even;
  foru(i, 1, n + 1) {
    if (i % 2) {
      odd.push_back(a[i]);
    } else {
      even.push_back(a[i]);
    }
  }
  if (n % 2 == 0) {
    reverse(even.begin(), even.end());
    foru(i, 0, even.size()) { cout << even[i] << " "; }
    foru(i, 0, odd.size()) { cout << odd[i] << " "; }
  } else {
    reverse(odd.begin(), odd.end());
    foru(i, 0, odd.size()) { cout << odd[i] << " "; }
    foru(i, 0, even.size()) { cout << even[i] << " "; }
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define dbgi(x) cout << #x << " = " << (x) << "\n";
#define dbgvi(x)                                                               \
  cout << #x << " = ";                                                         \
  for (int i = 0; i < (x.size()); ++i)                                         \
    cout << x[i] << " ";
#define mrk() cout << "HERE\n"
#define vi vector<int>
#define vs vector<string>
#define vii vector<vi>
#define viii vector<vii>
#define viiii vector<viii>
#define pii pair<int, int>
#define vpii vector<pii>
#define foru(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, b, a) for (int i = b; i > a; --i)
#define fastio()                                                               \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ld long double
using namespace std;

signed main() {
  int n;
  cin >> n;
  vi a(n + 1);
  foru(i, 1, n + 1) cin >> a[i];
  vi odd;
  vi even;
  foru(i, 1, n + 1) {
    if (i % 2) {
      odd.push_back(a[i]);
    } else {
      even.push_back(a[i]);
    }
  }
  if (n % 2 == 0) {
    reverse(even.begin(), even.end());
    foru(i, 0, even.size()) { cout << even[i] << " "; }
    foru(i, 0, odd.size()) { cout << odd[i] << " "; }
  } else {
    reverse(odd.begin(), odd.end());
    foru(i, 0, odd.size()) { cout << odd[i] << " "; }
    foru(i, 0, even.size()) { cout << even[i] << " "; }
  }
}
Problem p03675 (C++)

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

const int N = 1e5 + 5;
int n;
int ans[N];
deque<int> dque;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  bool rev = false;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (!rev)
      dque.push_back(x);
    else
      dque.push_front(x);
    rev = !rev;
  }
  n = 0;
  for (auto x : dque)
    ans[++n] = x;
  if (rev)
    reverse(ans + 1, ans + n + 1);
  for (int i = 1; i <= n; ++i) {
    cout << ans[i];
    if (i == n)
      cout << '\n';
    else
      cout << ' ';
  }
  return 0;
}


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

const int N = 2e5 + 5;
int n;
int ans[N];
deque<int> dque;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  bool rev = false;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (!rev)
      dque.push_back(x);
    else
      dque.push_front(x);
    rev = !rev;
  }
  n = 0;
  for (auto x : dque)
    ans[++n] = x;
  if (rev)
    reverse(ans + 1, ans + n + 1);
  for (int i = 1; i <= n; ++i) {
    cout << ans[i];
    if (i == n)
      cout << '\n';
    else
      cout << ' ';
  }
  return 0;
}
Problem p03675 (C++)

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

int a[100005], b[100005];
int n;

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

  if (n % 2 == 0) {
    int t = 1;
    for (int i = n / 2 + 1; i <= n; i++)
      b[i] = a[t], t += 2;
    t = 2;
    for (int i = n / 2; i >= 1; i--)
      b[i] = a[t], t += 2;
  } else {
    int t = 2;
    for (int i = n / 2 + 2; i <= n; i++)
      b[i] = a[t], t += 2;
    t = 1;
    for (int i = n / 2 + 1; i >= 1; i--)
      b[i] = a[t], t += 2;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}


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

int a[300005], b[300005];
int n;

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

  if (n % 2 == 0) {
    int t = 1;
    for (int i = n / 2 + 1; i <= n; i++)
      b[i] = a[t], t += 2;
    t = 2;
    for (int i = n / 2; i >= 1; i--)
      b[i] = a[t], t += 2;
  } else {
    int t = 2;
    for (int i = n / 2 + 2; i <= n; i++)
      b[i] = a[t], t += 2;
    t = 1;
    for (int i = n / 2 + 1; i >= 1; i--)
      b[i] = a[t], t += 2;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
// #define int long long
int main() {
  int N;
  int a[114514];
  int now = 0;
  cin >> N;
  REP(i, N) { cin >> a[i]; }
  if (N % 2 == 0) {
    REP(i, N / 2) {
      cout << a[N - 2 * i - 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
    REP(i, N / 2) {
      cout << a[2 * i];
      if (now != N - 1)
        cout << " ";
      now++;
    }
  } else {
    REP(i, N / 2) {
      cout << a[N - 2 * i - 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
    cout << a[0] << " ";
    REP(i, N / 2) {
      cout << a[2 * i + 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
// #define int long long
int main() {
  int N;
  int a[214514];
  int now = 0;
  cin >> N;
  REP(i, N) { cin >> a[i]; }
  if (N % 2 == 0) {
    REP(i, N / 2) {
      cout << a[N - 2 * i - 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
    REP(i, N / 2) {
      cout << a[2 * i];
      if (now != N - 1)
        cout << " ";
      now++;
    }
  } else {
    REP(i, N / 2) {
      cout << a[N - 2 * i - 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
    cout << a[0] << " ";
    REP(i, N / 2) {
      cout << a[2 * i + 1];
      if (now != N - 1)
        cout << " ";
      now++;
    }
  }
  cout << endl;

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[1000005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int r = 25000;
  int l = 25000;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      b[l--] = a[i];
    }
    if (i % 2) {
      b[l--] = a[i];

    } else {
      b[r++] = a[i];
    }
  }

  if (n % 2 == 0) {
    for (int i = l + 1; i < r; i++) {

      printf("%d", b[i]);
      if (i == r - 1)
        puts("");
      else
        printf(" ");
    }
  } else {
    for (int i = r - 1; i > l; i--) {
      printf("%d", b[i]);
      if (i == l + 1)
        puts("");
      else
        printf(" ");
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[1000005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int r = 250000;
  int l = 250000;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      b[l--] = a[i];
    }
    if (i % 2) {
      b[l--] = a[i];

    } else {
      b[r++] = a[i];
    }
  }

  if (n % 2 == 0) {
    for (int i = l + 1; i < r; i++) {

      printf("%d", b[i]);
      if (i == r - 1)
        puts("");
      else
        printf(" ");
    }
  } else {
    for (int i = r - 1; i > l; i--) {
      printf("%d", b[i]);
      if (i == l + 1)
        puts("");
      else
        printf(" ");
    }
  }
}