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

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

using namespace std;

int N, a[100009];

int main() {
  // freopen ("input", "r", stdin);
  // freopen ("output", "w", stdout);

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


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

using namespace std;

int N, a[200009];

int main() {
  // freopen ("input", "r", stdin);
  // freopen ("output", "w", stdout);

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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

int n;
int a[100000];
int b[100000];

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

  cin >> n;

  rep(i, n) cin >> a[i];
  int h = 0, t = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if ((n - i) & 1) {
      b[h++] = a[i];
    } else {
      b[t--] = a[i];
    }
  }
  cout << b[0];
  rep(i, n - 1) { cout << ' ' << b[i + 1]; }
  cout << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

int n;
int a[200000];
int b[200000];

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

  cin >> n;

  rep(i, n) cin >> a[i];
  int h = 0, t = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if ((n - i) & 1) {
      b[h++] = a[i];
    } else {
      b[t--] = a[i];
    }
  }
  cout << b[0];
  rep(i, n - 1) { cout << ' ' << b[i + 1]; }
  cout << endl;
  return 0;
}
Problem p03675 (C++)

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

int a[100005];
int b[100005];

int main() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  int j = 0;
  for (int i = n - 1; i >= 0; i -= 2)
    b[j++] = a[i];
  for (int i = n & 1; i < n; i += 2)
    b[j++] = a[i];
  rep(i, n) {
    cout << b[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << "\n";
  }
  return 0;
}


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

int a[200005];
int b[200005];

int main() {
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  int j = 0;
  for (int i = n - 1; i >= 0; i -= 2)
    b[j++] = a[i];
  for (int i = n & 1; i < n; i += 2)
    b[j++] = a[i];
  rep(i, n) {
    cout << b[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << "\n";
  }
  return 0;
}
Problem p03675 (C++)

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

int a[100001];

int main() {
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

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

  return 0;
}

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

int a[200001];

int main() {
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

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

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
int a[114514], b[114514];
int main() {
  int n;
  cin >> n;
  int x = 0, y = n - 1;
  rep(i, n) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    if (i % 2 == n % 2) {
      b[y] = a[i];
      y--;
    } else {
      b[x] = a[i];
      x++;
    }
  }
  rep(i, n) {
    cout << b[i];
    if (i < n - 1)
      cout << ' ';
    else
      cout << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
int a[214514], b[214514];
int main() {
  int n;
  cin >> n;
  int x = 0, y = n - 1;
  rep(i, n) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    if (i % 2 == n % 2) {
      b[y] = a[i];
      y--;
    } else {
      b[x] = a[i];
      x++;
    }
  }
  rep(i, n) {
    cout << b[i];
    if (i < n - 1)
      cout << ' ';
    else
      cout << endl;
  }
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define PI acos(-1.0)
#define N 20005
#define eps 1e-8
int n, i, a[N];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n % 2 == 0) {
    for (i = n; i > 0; i -= 2)
      printf("%d ", a[i]);
    for (i = 1; i <= n; i += 2)
      printf("%d ", a[i]);
  } else {
    for (i = n; i > 0; i -= 2)
      printf("%d ", a[i]);
    for (i = 2; i <= n; i += 2)
      printf("%d ", a[i]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define PI acos(-1.0)
#define N 200005
#define eps 1e-8
int n, i, a[N];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n % 2 == 0) {
    for (i = n; i > 0; i -= 2)
      printf("%d ", a[i]);
    for (i = 1; i <= n; i += 2)
      printf("%d ", a[i]);
  } else {
    for (i = n; i > 0; i -= 2)
      printf("%d ", a[i]);
    for (i = 2; i <= n; i += 2)
      printf("%d ", a[i]);
  }
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI (acos(-1.0))
#define mod 1000000007
#define maxn 100005
#define IN freopen("C.in", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std;

typedef tree<i64, null_type, less<i64>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

int a[100005];

int main() {
  int i, j, k, l, m, n;

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

  for (i = n; i >= 1; i -= 2) {
    printf("%d", a[i]);
    if (n != 1)
      printf(" ");
  }
  if (n % 2)
    i = 2;
  else
    i = 1;

  for (; i <= n; i += 2) {
    printf("%d", a[i]);
    if (i + 2 <= n)
      printf(" ");
  }

  printf("\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI (acos(-1.0))
#define mod 1000000007
#define maxn 100005
#define IN freopen("C.in", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std;

typedef tree<i64, null_type, less<i64>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

int a[200005];

int main() {
  int i, j, k, l, m, n;

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

  for (i = n; i >= 1; i -= 2) {
    printf("%d", a[i]);
    if (n != 1)
      printf(" ");
  }
  if (n % 2)
    i = 2;
  else
    i = 1;

  for (; i <= n; i += 2) {
    printf("%d", a[i]);
    if (i + 2 <= n)
      printf(" ");
  }

  printf("\n");
  return 0;
}
Problem p03675 (C++)

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

int n, a[100100];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  for (int i = n - 1; i >= 0; i -= 2)
    printf("%d ", a[i]);
  for (int i = n % 2; i < n; i += 2)
    printf("%d ", a[i]);
  printf("\n");

  return 0;
}


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

int n, a[200100];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a + i);
  for (int i = n - 1; i >= 0; i -= 2)
    printf("%d ", a[i]);
  for (int i = n % 2; i < n; i += 2)
    printf("%d ", a[i]);
  printf("\n");

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <deque>
#define f(i, a, b) for (register int i = (a), i##end = (b); i <= i##end; ++i)
const int neko = 100010;
int n, a[neko];
std::deque<int> q;
int main() {
  scanf("%d", &n);
  f(i, 1, n) scanf("%d", &a[i]);
  int opt = n & 1;
  f(i, 1, n) {
    if ((i & 1) ^ opt)
      q.push_back(a[i]);
    else
      q.push_front(a[i]);
  }
  while (!q.empty())
    printf("%d ", q.front()), q.pop_front();
  return 0;
}


Fixed submission:
#include <cstdio>
#include <deque>
#define f(i, a, b) for (register int i = (a), i##end = (b); i <= i##end; ++i)
const int neko = 200010;
int n, a[neko];
std::deque<int> q;
int main() {
  scanf("%d", &n);
  f(i, 1, n) scanf("%d", &a[i]);
  int opt = n & 1;
  f(i, 1, n) {
    if ((i & 1) ^ opt)
      q.push_back(a[i]);
    else
      q.push_front(a[i]);
  }
  while (!q.empty())
    printf("%d ", q.front()), q.pop_front();
  return 0;
}
Problem p03675 (C++)

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

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN];
int n;

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

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 2 * 1e5 + 10;
int a[MAXN];
int n;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LINF = (LLONG_MAX / 2);
const double eps = 1e-14;
const double PI = M_PI;
#define DEB cout << "!" << endl
#define SHOW(a, b) cout << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cout << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))
#define DIV 1000000007

int main() {
  int n;
  cin >> n;
  vi table(n);
  vi ans;
  rep(i, n) cin >> table[i];
  for (int j = n - 1; j > 0; j -= 2)
    ans.pb(table[j]);

  if (!n % 2)
    ans.pb(table[0]);
  for (int j = n % 2; j < n; j += 2)
    ans.pb(table[j]);
  for (int i = 0; i < n; i++) {
    cout << ans[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LINF = (LLONG_MAX / 2);
const double eps = 1e-14;
const double PI = M_PI;
#define DEB cout << "!" << endl
#define SHOW(a, b) cout << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cout << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))
#define DIV 1000000007

int main() {
  int n;
  cin >> n;
  vi table(n);
  vi ans;
  rep(i, n) cin >> table[i];
  for (int j = n - 1; j > 0; j -= 2)
    ans.pb(table[j]);

  if (n % 2 == 1)
    ans.pb(table[0]);
  for (int j = n % 2; j < n; j += 2)
    ans.pb(table[j]);
  for (int i = 0; i < n; i++) {
    cout << ans[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll n, a[100008], b[100008], ite;

int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n % 2 == 0) {
    ite = n / 2 + 1;
    for (ll i = 1; i <= n; i++) {
      b[ite] = a[i];
      ite += (i % 2 == 0) ? i : -i;
    }
  } else {
    ite = n / 2 + 1;
    for (ll i = 1; i <= n; i++) {
      b[ite] = a[i];
      ite += (i % 2 == 0) ? -i : i;
    }
  }

  for (ll i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll n, a[200008], b[200008], ite;

int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n % 2 == 0) {
    ite = n / 2 + 1;
    for (ll i = 1; i <= n; i++) {
      b[ite] = a[i];
      ite += (i % 2 == 0) ? i : -i;
    }
  } else {
    ite = n / 2 + 1;
    for (ll i = 1; i <= n; i++) {
      b[ite] = a[i];
      ite += (i % 2 == 0) ? -i : i;
    }
  }

  for (ll i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p03675 (C++)

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

using namespace std;

int a[100000];
int b[100000];

int main() {
  int n, i, j, k;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for (i = n - 1, j = 0, k = n - 1; i >= 0;) {
    b[j++] = a[i--];
    if (i >= 0)
      b[k--] = a[i--];
  }

  for (i = 0; i < n; i++) {
    if (i > 0)
      putchar(' ');

    printf("%d", b[i]);
  }
  puts("");

  return 0;
}


Fixed submission:
#include <cstdio>

using namespace std;

int a[200000];
int b[200000];

int main() {
  int n, i, j, k;

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);

  for (i = n - 1, j = 0, k = n - 1; i >= 0;) {
    b[j++] = a[i--];
    if (i >= 0)
      b[k--] = a[i--];
  }

  for (i = 0; i < n; i++) {
    if (i > 0)
      putchar(' ');

    printf("%d", b[i]);
  }
  puts("");

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, A[N], b = 0;
list<int> L;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i < n + 1; i++) {
    if (b % 2 == 0)
      L.push_back(A[i]);
    else
      L.push_front(A[i]);
    b++;
  }
  if (n % 2 == 0) {
    while (!L.empty()) {
      printf("%d ", L.front());
      L.pop_front();
    }
    return 0;
  }
  while (!L.empty()) {
    printf("%d ", L.back());
    L.pop_back();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, A[N], b = 0;
list<int> L;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i < n + 1; i++) {
    if (b % 2 == 0)
      L.push_back(A[i]);
    else
      L.push_front(A[i]);
    b++;
  }
  if (n % 2 == 0) {
    while (!L.empty()) {
      printf("%d ", L.front());
      L.pop_front();
    }
    return 0;
  }
  while (!L.empty()) {
    printf("%d ", L.back());
    L.pop_back();
  }
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
ll a[100000];
int o[100000];

int main() {
  cin >> N;
  rep(i, N) { cin >> a[i]; }

  {
    int i = 0;
    int c = N - 1;
    while (true) {
      o[i] = c;
      c -= 2;
      i++;
      if (c < 0) {
        c = -c - 1;
        break;
      }
    }

    while (true) {
      o[i] = c;
      c += 2;
      i++;
      if (c >= N) {
        break;
      }
    }
  }

  /*
  rep(i, N){
      cerr << o[i] << ",";
  }
  cerr << endl;
  */

  rep(i, N) {
    cout << a[o[i]];
    if (i < N - 1)
      cout << " ";
  }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
ll a[200000];
int o[200000];

int main() {
  cin >> N;
  rep(i, N) { cin >> a[i]; }

  {
    int i = 0;
    int c = N - 1;
    while (true) {
      o[i] = c;
      c -= 2;
      i++;
      if (c < 0) {
        c = -c - 1;
        break;
      }
    }

    while (true) {
      o[i] = c;
      c += 2;
      i++;
      if (c >= N) {
        break;
      }
    }
  }

  /*
  rep(i, N){
      cerr << o[i] << ",";
  }
  cerr << endl;
  */

  rep(i, N) {
    cout << a[o[i]];
    if (i < N - 1)
      cout << " ";
  }
  cout << endl;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n;
  int a[SIZE];

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }

  int cn = 0;

  vector<int> ans;

  for (int i = n / 2 * 2; i > 0; i -= 2) {
    ans.push_back(a[i - 1]);
  }
  for (int i = 1; i <= n; i += 2) {
    ans.push_back(a[i - 1]);
  }

  if (n % 2)
    reverse(ans.begin(), ans.end());

  for (int i = 0; i < n; i++) {
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int n;
  int a[SIZE];

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }

  int cn = 0;

  vector<int> ans;

  for (int i = n / 2 * 2; i > 0; i -= 2) {
    ans.push_back(a[i - 1]);
  }
  for (int i = 1; i <= n; i += 2) {
    ans.push_back(a[i - 1]);
  }

  if (n % 2)
    reverse(ans.begin(), ans.end());

  for (int i = 0; i < n; i++) {
    printf("%d%c", ans[i], " \n"[i == n - 1]);
  }

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) FOR(i, 0, b)
#define INF mugen
#define dump(x) cerr << #x << "=" << x << endl
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> P;
template <class T> void chmin(T &a, T const &b) {
  if (b < a)
    a = b;
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
using ll = long long;
const ll mod = LLONG_MAX;

int a[112345];
int main() {
  int n;
  cin >> n;
  FOR(i, 1, n + 1) cin >> a[i];
  if (n % 2 == 0) {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << ' ';
    }
    for (int i = 1; i <= n; i += 2) {
      cout << a[i] << ' ';
    }
    cout << endl;
  } else {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << ' ';
    }
    for (int i = 2; i <= n; i += 2) {
      cout << a[i] << ' ';
    }
    cout << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) FOR(i, 0, b)
#define INF mugen
#define dump(x) cerr << #x << "=" << x << endl
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int, int> P;
template <class T> void chmin(T &a, T const &b) {
  if (b < a)
    a = b;
}
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
using ll = long long;
const ll mod = LLONG_MAX;

int a[212345];
int main() {
  int n;
  cin >> n;
  FOR(i, 1, n + 1) cin >> a[i];
  if (n % 2 == 0) {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << ' ';
    }
    for (int i = 1; i <= n; i += 2) {
      cout << a[i] << ' ';
    }
    cout << endl;
  } else {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << ' ';
    }
    for (int i = 2; i <= n; i += 2) {
      cout << a[i] << ' ';
    }
    cout << endl;
  }
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
//
#include <cstdio>
using namespace std;
const int N = 100005;
int a[N], v[N], n, next[2][N], tag[N], fr, end, cnt;

void solve() {
  if (cnt == 0)
    v[++cnt] = a[1];
  fr = end = 1;
  for (int i = 2; i <= n; ++i) {
    v[++cnt] = a[i];
    int t = 0;
    if (next[0][end] != 0)
      t = 1;
    next[t][end] = cnt;
    next[!t][cnt] = end;
    int tt = fr;
    fr = cnt, end = tt;
  }
}

int main() {
  //	freopen("1.txt","r",stdin);
  //	freopen("11.txt","w",stdout);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  solve();
  int t = 0;
  if (next[1][fr])
    t = 1;
  for (int i = fr; i != end; i = next[t][i])
    printf("%d ", v[i]);
  printf("%d", v[end]);
  return 0;
}


Fixed submission:
//
#include <cstdio>
using namespace std;
const int N = 300005;
int a[N], v[N], n, next[2][N], tag[N], fr, end, cnt;

void solve() {
  if (cnt == 0)
    v[++cnt] = a[1];
  fr = end = 1;
  for (int i = 2; i <= n; ++i) {
    v[++cnt] = a[i];
    int t = 0;
    if (next[0][end] != 0)
      t = 1;
    next[t][end] = cnt;
    next[!t][cnt] = end;
    int tt = fr;
    fr = cnt, end = tt;
  }
}

int main() {
  //	freopen("1.txt","r",stdin);
  //	freopen("11.txt","w",stdout);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  solve();
  int t = 0;
  if (next[1][fr])
    t = 1;
  for (int i = fr; i != end; i = next[t][i])
    printf("%d ", v[i]);
  printf("%d", v[end]);
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

int n;
int a[100000]; // 10^5

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = n - 1; i >= 0; i -= 2) {
    cout << a[i] << " ";
  }
  int from = n % 2 ? 1 : 0;
  for (int i = from; i < n; i += 2) {
    cout << a[i] << " ";
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

int n;
int a[200000]; // 10^5

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = n - 1; i >= 0; i -= 2) {
    cout << a[i] << " ";
  }
  int from = n % 2 ? 1 : 0;
  for (int i = from; i < n; i += 2) {
    cout << a[i] << " ";
  }

  return 0;
}
Problem p03675 (C++)

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

using namespace std;

int ar[100010];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  int a = 0, b = n - 1;
  for (int i = n - 1; i >= 0; i -= 2) {
    cout << ar[i] << ' ';
  }
  int i;
  if (n % 2 == 0)
    i = 0;
  else
    i = 1;
  for (i; i < n; i += 2) {
    cout << ar[i] << ' ';
  }

  return 0;
}


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

using namespace std;

int ar[200010];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  int a = 0, b = n - 1;
  for (int i = n - 1; i >= 0; i -= 2) {
    cout << ar[i] << ' ';
  }
  int i;
  if (n % 2 == 0)
    i = 0;
  else
    i = 1;
  for (i; i < n; i += 2) {
    cout << ar[i] << ' ';
  }

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, ch;
int aa[100002];
int up = 50001, dn = 50001;
void push(int a[], int now) {
  if (now == 0) {
    aa[dn] = a[now];
    return;
  }
  push(a, now - 1);
  if (ch == 0) {
    dn--;
    aa[dn] = a[now];
    ch = 1;
    return;
  } else {
    up++;
    aa[up] = a[now];
    ch = 0;
    return;
  }
}
int main() {
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  push(a, n - 1);
  if (ch == 1) {
    for (int i = dn; i < up; i++) {
      cout << aa[i] << ' ';
    }
    cout << aa[up] << endl;
  } else {
    for (int i = up; i > dn; i--) {
      cout << aa[i] << ' ';
    }
    cout << aa[dn] << endl;
  }
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, ch;
int aa[200002];
int up = 100001, dn = 100001;
void push(int a[], int now) {
  if (now == 0) {
    aa[dn] = a[now];
    return;
  }
  push(a, now - 1);
  if (ch == 0) {
    dn--;
    aa[dn] = a[now];
    ch = 1;
    return;
  } else {
    up++;
    aa[up] = a[now];
    ch = 0;
    return;
  }
}
int main() {
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  push(a, n - 1);
  if (ch == 1) {
    for (int i = dn; i < up; i++) {
      cout << aa[i] << ' ';
    }
    cout << aa[up] << endl;
  } else {
    for (int i = up; i > dn; i--) {
      cout << aa[i] << ' ';
    }
    cout << aa[dn] << endl;
  }
  return (0);
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long lint;
const int N = 1e5 + 5;
int n, val[N];

namespace utils {
template <class T> inline void apn(T &x, const T y) { x > y ? x = y : 0; }
template <class T> inline void apx(T &x, const T y) { x < y ? x = y : 0; }
inline int nxi() {
  int x = 0;
  char c;
  while (((c = getchar()) > '9' || c < '0') && c != '-')
    ;
  const bool f = (c == '-') && (c = getchar());
  while (x = x * 10 - 48 + c, (c = getchar()) >= '0' && c <= '9')
    ;
  return f ? -x : x;
}
} // namespace utils
using namespace utils;

int main() {
  n = nxi();
  for (int i = 1; i <= n; ++i) {
    val[i] = nxi();
  }
  for (int i = n; i >= 1; i -= 2) {
    printf("%d ", val[i]);
  }
  for (int i = n & 1 ? 2 : 1; i <= n; i += 2) {
    printf("%d ", val[i]);
  }
  puts("");
  return 0;
}


Fixed submission:
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long lint;
const int N = 2e5 + 5;
int n, val[N];

namespace utils {
template <class T> inline void apn(T &x, const T y) { x > y ? x = y : 0; }
template <class T> inline void apx(T &x, const T y) { x < y ? x = y : 0; }
inline int nxi() {
  int x = 0;
  char c;
  while (((c = getchar()) > '9' || c < '0') && c != '-')
    ;
  const bool f = (c == '-') && (c = getchar());
  while (x = x * 10 - 48 + c, (c = getchar()) >= '0' && c <= '9')
    ;
  return f ? -x : x;
}
} // namespace utils
using namespace utils;

int main() {
  n = nxi();
  for (int i = 1; i <= n; ++i) {
    val[i] = nxi();
  }
  for (int i = n; i >= 1; i -= 2) {
    printf("%d ", val[i]);
  }
  for (int i = n & 1 ? 2 : 1; i <= n; i += 2) {
    printf("%d ", val[i]);
  }
  puts("");
  return 0;
}
Problem p03676 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 100000 + 5;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
using namespace std;

LL a[N];
LL inv[N];
LL fac[N];
map<LL, int> bucket;
void init() {
  fac[0] = 1;
  fac[1] = 1;
  inv[0] = 1;
  inv[1] = 1;
  for (LL i = 2; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
  }
  for (int i = 1; i < N; i++)
    inv[i] = inv[i] * inv[i - 1] % MOD;
}
LL C(LL n, LL m) {
  if (m > n)
    return 0;
  return ((fac[n] * inv[m] % MOD) * inv[n - m]) % MOD;
}
int main() {
  init();
  LL n;
  scanf("%lld", &n);
  LL pos = 0;
  for (int i = 1; i <= n + 1; i++) {
    scanf("%lld", a[i]);
    if (!bucket[a[i]])
      bucket[a[i]] = i;
    else
      pos = i;
  }
  for (int i = 0; i <= n; i++) {
    LL res = 0;
    res = (res + C(n + 1, i + 1)) % MOD;
    res = (res - C(n - pos + bucket[a[pos]], i)) % MOD;
    while (res < 0)
      res += MOD;
    printf("%lld\n", res);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9 + 7;
const int N = 100000 + 5;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
using namespace std;

LL a[N];
LL inv[N];
LL fac[N];
map<LL, int> bucket;
void init() {
  fac[0] = 1;
  fac[1] = 1;
  inv[0] = 1;
  inv[1] = 1;
  for (LL i = 2; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
  }
  for (int i = 1; i < N; i++)
    inv[i] = inv[i] * inv[i - 1] % MOD;
}
LL C(LL n, LL m) {
  if (m > n)
    return 0;
  return ((fac[n] * inv[m] % MOD) * inv[n - m]) % MOD;
}
int main() {
  init();
  LL n;
  scanf("%lld", &n);
  LL pos = 0;
  for (int i = 1; i <= n + 1; i++) {
    scanf("%lld", &a[i]);
    if (!bucket[a[i]])
      bucket[a[i]] = i;
    else
      pos = i;
  }
  for (int i = 0; i <= n; i++) {
    LL res = 0;
    res = (res + C(n + 1, i + 1)) % MOD;
    res = (res - C(n - pos + bucket[a[pos]], i)) % MOD;
    while (res < 0)
      res += MOD;
    printf("%lld\n", res);
  }

  return 0;
}
Problem p03676 (C++)

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

const int MAX = 2001;
const int MOD = 1000000007;
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() {
  int n;
  cin >> n;
  int a[n + 1];

  int p, q;
  map<int, int> m;
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
    if (m[a[i]] > 0) {
      p = m[a[i]] - 1;
      q = i;
    }
    m[a[i]] = i + 1;
  }
  COMinit();
  for (int i = 1; i <= n + 1; i++) {
    long long ans = COM(n + 1, i);
    ans -= COM(n + p - q, i - 1);
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
  }
}

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

const int MAX = 510000;
const int MOD = 1000000007;
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() {
  int n;
  cin >> n;
  int a[n + 1];

  int p, q;
  map<int, int> m;
  for (int i = 0; i <= n; i++) {
    cin >> a[i];
    if (m[a[i]] > 0) {
      p = m[a[i]] - 1;
      q = i;
    }
    m[a[i]] = i + 1;
  }
  COMinit();
  for (int i = 1; i <= n + 1; i++) {
    long long ans = COM(n + 1, i);
    ans -= COM(n + p - q, i - 1);
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
  }
}
Problem p03676 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 3e5 + 20;
int a[maxn], dp[maxn], pre[maxn];
const int MOD = 1e9 + 7;
LL fac[maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= maxn - 20; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
}
LL quick_pow(int a, int b, int MOD = 1e9 + 7) {
  LL ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = ans * base % MOD;
    b >>= 1;
    base = base * base % MOD;
  }
  return ans;
}
LL C(int n, int m) {
  if (n < m)
    return 0;
  if (n == m)
    return 1;
  return fac[n] * quick_pow(fac[m], MOD - 2) % MOD *
         quick_pow(fac[n - m], MOD - 2) % MOD;
}
int pos[maxn];
void work() {
  int n;
  scanf("%d", &n);
  int val;
  int one, two;
  for (int i = 1; i <= n + 1; ++i) {
    scanf("%d", &val);
    if (pos[val]) {
      one = pos[val], two = i;
    }
    pos[val] = i;
  }
  ++n;
  printf("%d\n", n - 1);
  for (int i = 2; i <= n; ++i) {
    LL ans = 0;
    for (int j = 0; j <= i - 1; ++j) {
      ans += C(one - 1, j) * C(n - two, i - 1 - j);
      if (ans >= MOD)
        ans %= MOD;
    }
    printf("%d\n", (C(n, i) + MOD - ans) % MOD);
  }
}

int main() {
#ifdef local
  freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
  init();
  work();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 3e5 + 20;
int a[maxn], dp[maxn], pre[maxn];
const int MOD = 1e9 + 7;
LL fac[maxn];
void init() {
  fac[0] = 1;
  for (int i = 1; i <= maxn - 20; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
}
LL quick_pow(int a, int b, int MOD = 1e9 + 7) {
  LL ans = 1, base = a;
  while (b) {
    if (b & 1)
      ans = ans * base % MOD;
    b >>= 1;
    base = base * base % MOD;
  }
  return ans;
}
LL C(int n, int m) {
  if (n < m)
    return 0;
  if (n == m)
    return 1;
  return fac[n] * quick_pow(fac[m], MOD - 2) % MOD *
         quick_pow(fac[n - m], MOD - 2) % MOD;
}
int pos[maxn];
void work() {
  int n;
  scanf("%d", &n);
  int val;
  int one, two;
  for (int i = 1; i <= n + 1; ++i) {
    scanf("%d", &val);
    if (pos[val]) {
      one = pos[val], two = i;
    }
    pos[val] = i;
  }
  ++n;
  printf("%d\n", n - 1);
  for (int i = 2; i <= n; ++i) {
    printf("%d\n", (C(n, i) + MOD - C(one - 1 + n - two, i - 1)) % MOD);
  }
}

int main() {
#ifdef local
  freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
  init();
  work();
  return 0;
}
Problem p03676 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
#define pb push_back
#define se second
#define fi first
using namespace std;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
int a[N], vis[N];
ll f[N], ans[N];

void pre() {
  f[0] = 1;
  for (ll i = 1; i < N; i++) {
    f[i] = (i * (f[i - 1] % mod)) % mod;
  }
}

ll power(ll x, ll y) {
  ll ret = 1;
  x %= mod;
  while (y) {
    if (y & 1) {
      ret = (ret * x) % mod;
    }
    y = y >> 1;
    x = (x * x) % mod;
  }
  return ret;
}

ll IE(ll x) { return power(x, mod - 2); }

ll C(ll m, ll r) { return (f[m] * ((IE(f[r]) * IE(f[m - r])) % mod)) % mod; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  pre();
  int n;
  cin >> n;
  for (int i = 1; i <= n + 1; i++) {
    ans[i] = C(n + 1, i) % mod;
  }
  int rep1 = -1, rep2 = -1, repnum;
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
    if (!vis[a[i]])
      vis[a[i]] = 1;
    else
      repnum = a[i];
  }
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == repnum) {
      if (rep1 == -1)
        rep1 = i;
      else
        rep2 = i;
    }
  }
  int sz2 = (n + 1 - rep2);
  /*for(int i=0;i<=sz2;i++){
      ll x=C(sz2,i);
      ans[i+1]=ans[i+1]-x;
  }*/
  int sz1 = (rep1 - 1);
  for (int i = 1; i <= (sz1 + sz2 + 1); i++) {
    ll sum = 0;
    for (int j = 1; j <= i; j++) {
      sum =
          (sum % mod + ((C(sz1, j - 1) % mod) * (C(sz2, i - j) % mod)) % mod) %
          mod;
    }
    ans[i] = (ans[i] - sum + mod) % mod;
  }
  for (int i = 1; i <= n + 1; i++)
    cout << ans[i] % mod << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define INF 0x3f3f3f3f
#define pb push_back
#define se second
#define fi first
using namespace std;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
int a[N], vis[N];
ll f[N], ans[N];

void pre() {
  f[0] = 1;
  for (ll i = 1; i < N; i++) {
    f[i] = (i * (f[i - 1] % mod)) % mod;
  }
}

ll power(ll x, ll y) {
  ll ret = 1;
  x %= mod;
  while (y) {
    if (y & 1) {
      ret = (ret * x) % mod;
    }
    y = y >> 1;
    x = (x * x) % mod;
  }
  return ret;
}

ll IE(ll x) { return power(x, mod - 2); }

ll C(ll m, ll r) { return (f[m] * ((IE(f[r]) * IE(f[m - r])) % mod)) % mod; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  pre();
  int n;
  cin >> n;
  for (int i = 1; i <= n + 1; i++) {
    ans[i] = C(n + 1, i) % mod;
  }
  int rep1 = -1, rep2 = -1, repnum;
  for (int i = 1; i <= n + 1; i++) {
    cin >> a[i];
    if (!vis[a[i]])
      vis[a[i]] = 1;
    else
      repnum = a[i];
  }
  for (int i = 1; i <= n + 1; i++) {
    if (a[i] == repnum) {
      if (rep1 == -1)
        rep1 = i;
      else
        rep2 = i;
    }
  }
  int sz2 = (n + 1 - rep2);
  /*for(int i=0;i<=sz2;i++){
      ll x=C(sz2,i);
      ans[i+1]=ans[i+1]-x;
  }*/
  int sz1 = (rep1 - 1);
  for (int i = 1; i <= (sz1 + sz2 + 1); i++) {
    ll sum = C(sz1 + sz2, i - 1) % mod;
    ans[i] = (ans[i] - sum + mod) % mod;
  }
  for (int i = 1; i <= n + 1; i++)
    cout << ans[i] % mod << endl;
  return 0;
}
Problem p03676 (C++)

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

int v[100009];
int fact[100009], invFact[100009];

#define MOD (1000 * 1000 * 1000 + 7)

inline int lgput(int a, int n) {
  int r = 1;
  while (n > 0) {
    if (n % 2)
      r = 1LL * r * a % MOD;
    n /= 2;
    a = 1LL * a * a % MOD;
  }
  return r;
}

inline int comb(int n, int k) {
  return 1LL * fact[n] * invFact[n - k] % MOD * invFact[k] % MOD;
}

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

  int sol = 0;
  for (int i = 1; i <= n + 1; i++) {
    int x;
    scanf("%d", &x);
    if (v[x] != 0)
      sol = i - v[x];
    v[x] = i;
  }

  fact[0] = 1;
  for (int i = 1; i <= n + 1; i++)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invFact[n + 1] = lgput(fact[n + 1], MOD - 2);
  for (int i = n; i >= 0; i--)
    invFact[i] = 1LL * (i + 1) * invFact[i + 1] % MOD;

  for (int i = 1; i <= n + 1; i++) {
    int ans = comb(n + 1, i);
    ans -= comb(n - sol, i - 1);
    if (ans < 0)
      ans += MOD;
    printf("%d\n", ans);
  }

  return 0;
}


Fixed submission:
#include <cstdio>

int v[100009];
int fact[100009], invFact[100009];

#define MOD (1000 * 1000 * 1000 + 7)

inline int lgput(int a, int n) {
  int r = 1;
  while (n > 0) {
    if (n % 2)
      r = 1LL * r * a % MOD;
    n /= 2;
    a = 1LL * a * a % MOD;
  }
  return r;
}

inline int comb(int n, int k) {
  if (n < k)
    return 0;
  return 1LL * fact[n] * invFact[n - k] % MOD * invFact[k] % MOD;
}

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

  int sol = 0;
  for (int i = 1; i <= n + 1; i++) {
    int x;
    scanf("%d", &x);
    if (v[x] != 0)
      sol = i - v[x];
    v[x] = i;
  }

  fact[0] = 1;
  for (int i = 1; i <= n + 1; i++)
    fact[i] = 1LL * i * fact[i - 1] % MOD;
  invFact[n + 1] = lgput(fact[n + 1], MOD - 2);
  for (int i = n; i >= 0; i--)
    invFact[i] = 1LL * (i + 1) * invFact[i + 1] % MOD;

  for (int i = 1; i <= n + 1; i++) {
    int ans = comb(n + 1, i);
    ans -= comb(n - sol, i - 1);
    if (ans < 0)
      ans += MOD;
    printf("%d\n", ans);
  }

  return 0;
}
Problem p03676 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MN = 100100;
const LL MOD = 1e9 + 7;
int n, a[MN], cnt[MN] = {0}, pos[10] = {0};
LL fac[MN], inv[MN];
LL QuickPow(LL x, LL y) {
  LL res = 1;
  while (y) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return res;
}
int main() {
  fac[0] = 1;
  int N = MN - 10;
  for (int i = 1; i <= N; i++)
    fac[i] = (i * fac[i - 1]) % MOD;
  inv[N] = QuickPow(fac[N], MOD - 2);
  for (int i = N - 1; i >= 0; i--)
    inv[i] = ((inv[i + 1]) * (i + 1)) % MOD;
  scanf("%d", &n);
  for (int i = 1; i <= n + 1; i++)
    scanf("%d", &a[i]), cnt[a[i]]++;
  int d = 0, flag = 0;
  for (int i = 1; i <= n + 1; i++)
    if (cnt[a[i]] == 2 && (!flag))
      flag = 1, d = i;
    else if (cnt[a[i]] == 2 && flag)
      d = i - d + 1;
  for (int k = 1; k <= n + 1; k++)
    printf(
        "%lld\n",
        ((fac[n + 1] % MOD * inv[k] % MOD * inv[n + 1 - k] % MOD) % MOD -
         (fac[n + 1 - d] % MOD * inv[k - 1] % MOD * inv[n - d - k + 2] % MOD) %
             MOD +
         MOD) %
            MOD);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MN = 100100;
const LL MOD = 1e9 + 7;
int n, a[MN], cnt[MN] = {0}, pos[10] = {0};
LL fac[MN], inv[MN];
LL QuickPow(LL x, LL y) {
  LL res = 1;
  while (y) {
    if (y & 1)
      res = (res * x) % MOD;
    x = (x * x) % MOD;
    y >>= 1;
  }
  return res;
}
int main() {
  fac[0] = 1;
  int N = MN - 10;
  for (int i = 1; i <= N; i++)
    fac[i] = (i * fac[i - 1]) % MOD;
  inv[N] = QuickPow(fac[N], MOD - 2);
  for (int i = N - 1; i >= 0; i--)
    inv[i] = ((inv[i + 1]) * (i + 1)) % MOD;
  scanf("%d", &n);
  for (int i = 1; i <= n + 1; i++)
    scanf("%d", &a[i]), cnt[a[i]]++;
  int d = 0, flag = 0;
  for (int i = 1; i <= n + 1; i++)
    if (cnt[a[i]] == 2 && (!flag))
      flag = 1, d = i;
    else if (cnt[a[i]] == 2 && flag)
      d = i - d + 1;
  for (int k = 1; k <= n + 1; k++) {
    if (n + 1 - d < k - 1)
      printf("%lld\n",
             (fac[n + 1] % MOD * inv[k] % MOD * inv[n + 1 - k] % MOD) % MOD);
    else
      printf("%lld\n",
             ((fac[n + 1] % MOD * inv[k] % MOD * inv[n + 1 - k] % MOD) % MOD -
              (fac[n + 1 - d] % MOD * inv[k - 1] % MOD * inv[n - d - k + 2] %
               MOD) %
                  MOD +
              MOD) %
                 MOD);
  }
  return 0;
}