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

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

/*
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i++)
#define Rep(i, j, k) for (int i = j; i >= k; i--)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template <typename t> t read() {
  t x = 0;
  int f = 1;
  char c = getchar();
  while (c > '9' || c < '0')
    f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - 48, c = getchar();
  return x * f;
}

template <typename t> void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
    return;
  }
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + 48);
}

const int N = 1e5 + 10;
int a[N], b[N], n;

int main() {
  //	freopen(".in", "r", stdin);
  //	freopen(".out", "w", stdout);
  n = rdi();
  for (int i = 1; i <= n; i++)
    a[i] = rdi();
  int l = 1, r = n, k = 0;
  for (int i = n; i; i--) {
    if (!k)
      b[l++] = a[i];
    else
      b[r--] = a[i];
    k ^= 1;
  }
  for (int i = 1; i <= n; i++)
    write(b[i]), putchar(32);
  return 0;
}


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

/*
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i++)
#define Rep(i, j, k) for (int i = j; i >= k; i--)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template <typename t> t read() {
  t x = 0;
  int f = 1;
  char c = getchar();
  while (c > '9' || c < '0')
    f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - 48, c = getchar();
  return x * f;
}

template <typename t> void write(t x) {
  if (x < 0) {
    putchar('-'), write(-x);
    return;
  }
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + 48);
}

const int N = 3e5 + 10;
int a[N], b[N], n;

int main() {
  //	freopen(".in", "r", stdin);
  //	freopen(".out", "w", stdout);
  n = rdi();
  for (int i = 1; i <= n; i++)
    a[i] = rdi();
  int l = 1, r = n, k = 0;
  for (int i = n; i; i--) {
    if (!k)
      b[l++] = a[i];
    else
      b[r--] = a[i];
    k ^= 1;
  }
  for (int i = 1; i <= n; i++)
    write(b[i]), putchar(32);
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k[112345];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
  }
  if (n % 2 == 1) {
    for (int i = n - 1; i >= 0; i -= 2) {
      cout << k[i] << " ";
    }
    for (int i = 1; i <= n - 1; i += 2) {
      cout << k[i] << " ";
    }
  } else {
    for (int i = n - 1; i >= 1; i -= 2) {
      cout << k[i] << " ";
    }
    for (int i = 0; i <= n - 2; i += 2) {
      cout << k[i] << " ";
    }
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k[200000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
  }
  if (n % 2 == 1) {
    for (int i = n - 1; i >= 0; i -= 2) {
      cout << k[i] << " ";
    }
    for (int i = 1; i <= n - 1; i += 2) {
      cout << k[i] << " ";
    }
  } else {
    for (int i = n - 1; i >= 1; i -= 2) {
      cout << k[i] << " ";
    }
    for (int i = 0; i <= n - 2; i += 2) {
      cout << k[i] << " ";
    }
  }
  cout << endl;
}
Problem p03675 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> res;
  for (int i = 0; i < n; i++) {
    res.push_back(a[i]);
    reverse(res.begin(), res.end());
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
  cout << ""
       << "\n";
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int res[n];
  if (n % 2) {
    for (int i = 0; i < n; i++) {
      if (i % 2)
        res[n / 2 + i / 2 + 1] = a[i];
      else
        res[n / 2 - i / 2] = a[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2)
        res[n / 2 - i / 2 - 1] = a[i];
      else
        res[n / 2 + i / 2] = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
  cout << ""
       << "\n";
  return 0;
}
Problem p03675 (C++)

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

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

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

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

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

const int MAX_N = 1e5 + 10;
int a[MAX_N];
int N;
void solve() {
  deque<int> que;
  for (int i = 0; i < N; ++i) {
    if (i % 2)
      que.push_front(a[i]);
    else
      que.push_back(a[i]);
  }
  if (N % 2)
    reverse(que.begin(), que.end());
  for (int i = 0; i < N - 1; ++i) {
    cout << que[i] << " ";
  }
  cout << que.back() << endl;
}

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

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

const int MAX_N = 2e5 + 10;
int a[MAX_N];
int N;
void solve() {
  deque<int> que;
  for (int i = 0; i < N; ++i) {
    if (i % 2)
      que.push_front(a[i]);
    else
      que.push_back(a[i]);
  }
  if (N % 2)
    reverse(que.begin(), que.end());
  for (int i = 0; i < N - 1; ++i) {
    cout << que[i] << " ";
  }
  cout << que.back() << endl;
}

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n;
int a[100000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  vector<int> b;
  for (int i = n - 1; i >= 0; i -= 2) {
    b.pb(a[i]);
  }
  for (int i = n % 2; i < n; i += 2)
    b.pb(a[i]);
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n;
int a[200000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  vector<int> b;
  for (int i = n - 1; i >= 0; i -= 2) {
    b.pb(a[i]);
  }
  for (int i = n % 2; i < n; i += 2)
    b.pb(a[i]);
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);

  return 0;
}
Problem p03675 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = [A[0]]
for i in range(1, N):
    if i % 2 == 0:
        ans.append(A[i])
    else:
        ans.insert(0, A[i])

if N % 2 == 1:
    ans = ans[::-1]

print(" ".join(list(map(str, ans))))


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

ans = []
if N % 2 == 0:
    l1 = A[0::2]
    l2 = A[1::2]
    l2 = l2[::-1]
    ans = l2 + l1
else:
    l1 = A[0::2]
    l2 = A[1::2]
    l1 = l1[::-1]
    ans = l1 + l2

print(" ".join(list(map(str, ans))))
Problem p03675 (C++)

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss, b) memset(ss, b, sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;

int a[N];
vector<int> ans;
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n & 1) {
    int sz = n;
    while (sz > 0) {
      ans.pb(a[sz]);
      sz -= 2;
    }
    sz = 2;
    while (sz < n) {
      ans.pb(a[sz]);
      sz += 2;
    }
  } else {
    int sz = n;
    while (sz > 0) {
      ans.pb(a[sz]);
      sz -= 2;
    }
    sz = 1;
    while (sz < n) {
      ans.pb(a[sz]);
      sz += 2;
    }
  }
  for (auto x : ans)
    printf("%d ", x);
  puts("");
  return 0;
}

//    lower_bound()
//    __builtin_popcount()
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    const double eps=1e-12;
//    #pragma comment(linker,"/STACK:102400000,102400000")


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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss, b) memset(ss, b, sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;

int a[N];
vector<int> ans;
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n & 1) {
    int sz = n;
    while (sz > 0) {
      ans.pb(a[sz]);
      sz -= 2;
    }
    sz = 2;
    while (sz < n) {
      ans.pb(a[sz]);
      sz += 2;
    }
  } else {
    int sz = n;
    while (sz > 0) {
      ans.pb(a[sz]);
      sz -= 2;
    }
    sz = 1;
    while (sz < n) {
      ans.pb(a[sz]);
      sz += 2;
    }
  }
  for (auto x : ans)
    printf("%d ", x);
  puts("");
  return 0;
}

//    lower_bound()
//    __builtin_popcount()
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    const double eps=1e-12;
//    #pragma comment(linker,"/STACK:102400000,102400000")
Problem p03675 (Python)

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

b = []
for i in range(n):
    b.append(a[i])
    b.reverse()

print(" ".join(map(str, b)))


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

b = list(reversed(a[1::2])) + a[0::2]
print(" ".join(map(str, b if n % 2 == 0 else reversed(b))))
Problem p03675 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
an = list(input().split())
b = []

cnt = 1
for i in an:
    if cnt % 2 == 0:
        b.insert(0, i)
    else:
        b.append(i)
    cnt += 1

if n % 2 == 1:
    b.reverse()

print(" ".join(b))


Fixed submission:
n = int(input())
a = list(input().split())
if n == 1:
    print(a[0])
elif n % 2:
    print(*(a[-1::-2] + a[1::2]))
else:
    print(*(a[-1::-2] + a[0::2]))
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int MAXN = (1 << 30);
const int maxn = 100000 + 50;
const int mod = 1e9 + 7;
int a[maxn], n;
int main() {
  // freopen("input.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n & 1) {
    for (int i = n; i >= 1; i -= 2)
      cout << a[i] << " ";
    for (int i = 2; i <= n - 1; i += 2)
      cout << a[i] << " ";
  } else {
    for (int i = n; i >= 2; i -= 2)
      cout << a[i] << " ";
    for (int i = 1; i <= n - 1; i += 2)
      cout << a[i] << " ";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int MAXN = (1 << 30);
const int maxn = 200000 + 50;
const int mod = 1e9 + 7;
int a[maxn], n;
int main() {
  // freopen("input.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n & 1) {
    for (int i = n; i >= 1; i -= 2)
      cout << a[i] << " ";
    for (int i = 2; i <= n - 1; i += 2)
      cout << a[i] << " ";
  } else {
    for (int i = n; i >= 2; i -= 2)
      cout << a[i] << " ";
    for (int i = 1; i <= n - 1; i += 2)
      cout << a[i] << " ";
  }
  return 0;
}
Problem p03675 (Python)

Buggy submission (status: Runtime Error):
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque([])
rev = 1
for i in a:
    if rev == 1:
        b.append(i)
        rev = -1
    elif rev == -1:
        b.appendleft(i)
        rev = 1

print(*(b if rev == 1 else b[::-1]))


Fixed submission:
from collections import deque

n = int(input())
a = list(map(int, input().split()))

b = deque([])
rev = 1
for i in a:
    if rev == 1:
        b.append(i)
        rev = -1
    elif rev == -1:
        b.appendleft(i)
        rev = 1

print(*(b if rev == 1 else list(b)[::-1]))
Problem p03675 (C++)

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

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

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


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

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

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

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

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


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

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

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

using namespace std;

int main() {
  int a[200001];
  vector<int> b;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }
  for (int i = 0; i < N; i++) {
    cout << b[i];
    if (i != N - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int a[200001];
  vector<int> b;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0)
      b.push_back(a[i]);
    else
      b.insert(b.begin(), a[i]);
  }
  if (N % 2 == 1) {
    reverse(b.begin(), b.end());
  }
  for (int i = 0; i < N; i++) {
    cout << b[i];
    if (i != N - 1)
      cout << " ";
    else
      cout << endl;
  }
  return 0;
}
Problem p03675 (C++)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  // cout.precision(10);
  bool reverse = false;
  int n;
  cin >> n;
  int a[100050];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << a[1] << endl;
    return 0;
  }
  for (int i = n; i >= 1; i -= 2) {
    cout << a[i] << " ";
  }
  for (int i = n % 2 + 1; i <= n; i += 2) {
    cout << a[i];
    if (i >= (n - 1)) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

#define ALL(a) (a).begin(), a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

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

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

#define ALL(a) (a).begin(), a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; n >= i; i++)
    cin >> a[i];
  bool check = false;
  int j = n;
  while (j >= 1) {
    if (check)
      cout << ' ';
    cout << a[j];
    j -= 2;
    check = true;
  }
  if (n % 2 == 1)
    j = 2;
  else
    j = 1;
  while (n >= j) {
    cout << ' ' << a[j];
  }
  cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; n >= i; i++)
    cin >> a[i];
  bool check = false;
  int j = n;
  while (j >= 1) {
    if (check)
      cout << ' ';
    cout << a[j];
    j -= 2;
    check = true;
  }
  if (n % 2 == 1)
    j = 2;
  else
    j = 1;
  while (n >= j) {
    cout << ' ' << a[j];
    j += 2;
  }
  cout << endl;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

int n;
int a[100000];

int main(int argc, char **argv) {
  cin >> n;
  REP(i, n) cin >> a[i];
  REP(i, n) {
    if (i != 0)
      cout << ' ';
    if (i < (n + 1) / 2)
      cout << a[n - 1 - i * 2];
    else
      cout << a[n % 2 + (i - (n + 1) / 2) * 2];
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v, 0, sizeof(v))
#define MP(a, b) make_pair((a), (b))
#define ABS(a) ((a) > 0 ? (a) : -(a))
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)

int n;
int a[200000];

int main(int argc, char **argv) {
  cin >> n;
  REP(i, n) cin >> a[i];
  REP(i, n) {
    if (i != 0)
      cout << ' ';
    if (i < (n + 1) / 2)
      cout << a[n - 1 - i * 2];
    else
      cout << a[n % 2 + (i - (n + 1) / 2) * 2];
  }
  cout << endl;
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int n, a[111111], p, q, ans[111111];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    p = n - i + 1;
    if (p % 2)
      q = 1 + p / 2;
    else
      q = i + p / 2;
    ans[q] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int n, a[222222], p, q, ans[222222];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    p = n - i + 1;
    if (p % 2)
      q = 1 + p / 2;
    else
      q = i + p / 2;
    ans[q] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FO(x)                                                                  \
  {                                                                            \
    freopen(#x ".in", "r", stdin);                                             \
    freopen(#x ".out", "w", stdout);                                           \
  }
#define fir first
#define sec second
using namespace std;
typedef long long ll;
template <typename T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int a[201234];
int main() {
  int i, n, f = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (i = n; i; i -= 2)
    printf("%d ", a[i]);
  for (i = (n & 1 ? 2 : 1); i <= n; i += 2) {
    printf("%d ", a[i]);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FO(x)                                                                  \
  {                                                                            \
    freopen(#x ".in", "r", stdin);                                             \
    freopen(#x ".out", "w", stdout);                                           \
  }
#define fir first
#define sec second
using namespace std;
typedef long long ll;
template <typename T> inline bool cmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool cmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int a[201234];
int main() {
  int i, n, f = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (i = n; i > 0; i -= 2)
    printf("%d ", a[i]);
  for (i = (n & 1 ? 2 : 1); i <= n; i += 2) {
    printf("%d ", a[i]);
  }
  return 0;
}
Problem p03675 (C++)

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  int ans;
  int N;
  cin >> N;
  vector<LL> a(N);
  FOR(i, 0, N) { cin >> a[i]; }

  vector<LL> b;
  FOR(i, 0, N) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }

  FOR(i, 0, N) { cout << b[i] << ' '; }

  cout << '\n';

  return 0;
}

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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  int ans;
  int N;
  cin >> N;
  vector<LL> a(N);
  FOR(i, 0, N) { cin >> a[i]; }

  vector<LL> b(N);

  int a_index = N - 1;
  int b_index = 0;
  while (a_index >= 0) {
    b[b_index] = a[a_index];
    a_index -= 2;
    b_index++;
  }

  a_index = N % 2;
  while (a_index < N) {
    b[b_index] = a[a_index];
    a_index += 2;
    b_index++;
  }

  FOR(i, 0, N) { cout << b[i] << ' '; }

  cout << '\n';

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int a[100010];
  rep(i, N) cin >> a[i];
  deque<int> dq;
  rep(i, N) {
    if (N % 2 != i % 2)
      dq.push_front(a[i]);
    else
      dq.push_back(a[i]);
  }
  rep(i, N) {
    if (i != 0)
      cout << " ";
    cout << dq[i];
  }
  cout << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int a[200010];
  rep(i, N) cin >> a[i];
  deque<int> dq;
  rep(i, N) {
    if (N % 2 != i % 2)
      dq.push_front(a[i]);
    else
      dq.push_back(a[i]);
  }
  rep(i, N) {
    if (i != 0)
      cout << " ";
    cout << dq[i];
  }
  cout << endl;

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "math.h"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
  long long int tmp = 1;

  if (n > 0) {
    tmp = power(x, n / 2, M);
    if (n % 2 == 0)
      tmp = (tmp * tmp) % M;
    else
      tmp = (((tmp * tmp) % M) * x) % M;
  }
  return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  int num[100000] = {};
  for (int i = 0; i < N; i++)
    cin >> num[i];
  if (N % 2) {
    for (int i = N - 1; i >= 0; i -= 2)
      cout << num[i] << " ";
    for (int i = 1; i < N; i += 2)
      cout << num[i] << " ";
    cout << endl;
    return 0;
  }
  for (int i = N - 1; i >= 0; i -= 2)
    cout << num[i] << " ";
  for (int i = 0; i < N; i += 2)
    cout << num[i] << " ";
  cout << endl;
  return 0;
}

Fixed submission:
#include "algorithm"
#include "climits"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "math.h"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
  long long int tmp = 1;

  if (n > 0) {
    tmp = power(x, n / 2, M);
    if (n % 2 == 0)
      tmp = (tmp * tmp) % M;
    else
      tmp = (((tmp * tmp) % M) * x) % M;
  }
  return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  int num[200000] = {};
  for (int i = 0; i < N; i++)
    cin >> num[i];
  if (N % 2) {
    for (int i = N - 1; i >= 0; i -= 2)
      cout << num[i] << " ";
    for (int i = 1; i < N; i += 2)
      cout << num[i] << " ";
    cout << endl;
    return 0;
  }
  for (int i = N - 1; i >= 0; i -= 2)
    cout << num[i] << " ";
  for (int i = 0; i < N; i += 2)
    cout << num[i] << " ";
  cout << endl;
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

vector<int> b;
int a[30010];
int n;

int main() {
  cin >> n;
  REP(i, n) scanf("%d", &a[i]);

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

  cout << endl;

  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

vector<int> b;
int a[300100];
int n;

int main() {
  cin >> n;
  REP(i, n) scanf("%d", &a[i]);

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

  cout << endl;

  return 0;
}
Problem p03675 (C++)

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

using namespace std;

int n, a[20020];

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

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

using namespace std;

int n, a[200020];

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int one, two, a[100001], c[100001], d[100001];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i += 2) {
    c[++one] = a[i];
  }
  for (int i = 2; i <= n; i += 2) {
    d[++two] = a[i];
  }
  if (n % 2 == 0) {
    for (int i = two; i >= 1; i--)
      printf("%d ", d[i]);
    for (int i = 1; i <= one; i++)
      printf("%d ", c[i]);
  }
  if (n % 2 == 1) {
    for (int i = one; i >= 1; i--)
      printf("%d ", c[i]);
    for (int i = 1; i <= two; i++)
      printf("%d ", d[i]);
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int one, two, a[1000001], c[1000001], d[1000001];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i += 2) {
    c[++one] = a[i];
  }
  for (int i = 2; i <= n; i += 2) {
    d[++two] = a[i];
  }
  if (n % 2 == 0) {
    for (int i = two; i >= 1; i--)
      printf("%d ", d[i]);
    for (int i = 1; i <= one; i++)
      printf("%d ", c[i]);
  }
  if (n % 2 == 1) {
    for (int i = one; i >= 1; i--)
      printf("%d ", c[i]);
    for (int i = 1; i <= two; i++)
      printf("%d ", d[i]);
  }
}
Problem p03675 (C++)

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

int N, A[100010];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &A[i]);
  for (int i = 0; i < N; i += 2) {
    printf("%d ", A[N - i - 1]);
  }
  for (int i = 1; i < N / 2 + 1; i++) {
    printf("%d", A[i * 2 - 1 - (N % 2 == 0)]);
    if (i == N / 2)
      continue;
    printf(" ");
  }
  printf("\n");
  return 0;
}


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

int N, A[200010];

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

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")

using namespace std;

#define int long long
// typedef    long long          ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> P;

const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;

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

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

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")

using namespace std;

#define int long long
// typedef    long long          ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> P;

const int INF = 1e+9;
const double EPS = 1e-9;
const int MOD = 1000000007;

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

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

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

int a[60000], p1 = 30000, p2 = 30001, n;
using namespace std;
int main() {
  scanf("%d", &n);
  int dir = 2;
  for (int i = 0; i < n; i++) {
    dir = 3 - dir;
    if (dir == 1) {
      scanf("%d", a + p2);
      p2++;
    } else {
      scanf("%d", a + p1);
      p1--;
    }
  }
  if (dir == 2) {
    for (int i = p1 + 1; i < p2 - 1; i++)
      printf("%d ", a[i]);
    printf("%d\n", a[p2 - 1]);
  }

  else {
    for (int i = p2 - 1; i > p1 + 1; i--)
      printf("%d ", a[i]);
    printf("%d\n", a[p1 + 1]);
  }

  return 0;
}

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

int a[600000], p1 = 300000, p2 = 300001, n;
using namespace std;
int main() {
  scanf("%d", &n);
  int dir = 2;
  for (int i = 0; i < n; i++) {
    dir = 3 - dir;
    if (dir == 1) {
      scanf("%d", a + p2);
      p2++;
    } else {
      scanf("%d", a + p1);
      p1--;
    }
  }
  if (dir == 2) {
    for (int i = p1 + 1; i < p2 - 1; i++)
      printf("%d ", a[i]);
    printf("%d\n", a[p2 - 1]);
  }

  else {
    for (int i = p2 - 1; i > p1 + 1; i--)
      printf("%d ", a[i]);
    printf("%d\n", a[p1 + 1]);
  }

  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
int main() {
  static int n, a[100005], b[100005];
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", a + i);
  if (n & 1) {
    b[n / 2 + 1] = a[1];
    int cnt = 1;
    rep(i, 1, n / 2) b[n / 2 + i + 1] = a[++cnt], b[n / 2 - i + 1] = a[++cnt];
  } else {
    b[n / 2 + 1] = a[1];
    int cnt = 1;
    rep(i, 1, n / 2) {
      b[n / 2 + 1 - i] = a[++cnt];
      if (i != n / 2)
        b[n / 2 + 1 + i] = a[++cnt];
    }
  }
  rep(i, 1, n - 1) printf("%d ", b[i]);
  printf("%d\n", b[n]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
int main() {
  static int n, a[200005], b[200005];
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", a + i);
  if (n & 1) {
    b[n / 2 + 1] = a[1];
    int cnt = 1;
    rep(i, 1, n / 2) b[n / 2 + i + 1] = a[++cnt], b[n / 2 - i + 1] = a[++cnt];
  } else {
    b[n / 2 + 1] = a[1];
    int cnt = 1;
    rep(i, 1, n / 2) {
      b[n / 2 + 1 - i] = a[++cnt];
      if (i != n / 2)
        b[n / 2 + 1 + i] = a[++cnt];
    }
  }
  rep(i, 1, n - 1) printf("%d ", b[i]);
  printf("%d\n", b[n]);
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <queue>

#define gec getchar
#define FILE(F) freopen(F ".in", "r", stdin), freopen(F ".out", "w", stdout)
#define DEBUG                                                                  \
  fprintf(stderr, "Passing [%s] in Line (%d)\n", __FUNCTION__, __LINE__)

typedef long long ll;
template <typename T> inline void read(T &x) {
  x = 0;
  bool f = 0;
  char c = gec();
  for (; c < '0' || c > '9'; c = gec())
    f = (c == '-');
  for (; c >= '0' && c <= '9'; c = gec())
    x = x * 10 + c - '0';
  x = f ? -x : x;
}

const int MAXN(200010);
std::deque<int> que;
int n, a[MAXN], Now, _n;
int main() {
#ifndef ONLINE__JUDGE
  FILE("C");
#endif
  read(n);
  for (int i = 1; i <= n; i++)
    read(a[i]);
  Now = 0;
  for (int i = 1; i <= n; i++) {
    Now ^= 1;
    if (Now)
      que.push_back(a[i]);
    else
      que.push_front(a[i]);
  }
  while (!que.empty())
    a[++_n] = que.front(), que.pop_front();
  if (!Now)
    for (int i = 1; i <= n; i++)
      printf("%d ", a[i]);
  else
    for (int i = 1; i <= n; i++)
      printf("%d ", a[n - i + 1]);
  printf("\n");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <queue>

#define gec getchar
#define FILE(F) freopen(F ".in", "r", stdin), freopen(F ".out", "w", stdout)
#define DEBUG                                                                  \
  fprintf(stderr, "Passing [%s] in Line (%d)\n", __FUNCTION__, __LINE__)

typedef long long ll;
template <typename T> inline void read(T &x) {
  x = 0;
  bool f = 0;
  char c = gec();
  for (; c < '0' || c > '9'; c = gec())
    f = (c == '-');
  for (; c >= '0' && c <= '9'; c = gec())
    x = x * 10 + c - '0';
  x = f ? -x : x;
}

const int MAXN(200010);
std::deque<int> que;
int n, a[MAXN], Now, _n;
int main() {
  read(n);
  for (int i = 1; i <= n; i++)
    read(a[i]);
  Now = 0;
  for (int i = 1; i <= n; i++) {
    Now ^= 1;
    if (Now)
      que.push_back(a[i]);
    else
      que.push_front(a[i]);
  }
  while (!que.empty())
    a[++_n] = que.front(), que.pop_front();
  if (!Now)
    for (int i = 1; i <= n; i++)
      printf("%d ", a[i]);
  else
    for (int i = 1; i <= n; i++)
      printf("%d ", a[n - i + 1]);
  printf("\n");
  return 0;
}
Problem p03675 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
const int M = 1e5 + 10;
int a[M], b[M];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int flag = 0;
  int l = 1, r = n;
  for (int i = n; i >= 1; i--) {
    if (flag == 0) {
      b[l] = a[i];
      l++;
      flag = 1;
      continue;
    } else {
      b[r] = a[i];
      r--;
      flag = 0;
    }
  }
  for (int i = 1; i <= n; i++)
    cout << b[i] << ' ';
  cout << endl;
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
const int M = 2e5 + 10;
int a[M], b[M];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  int flag = 0;
  int l = 1, r = n;
  for (int i = n; i >= 1; i--) {
    if (flag == 0) {
      b[l] = a[i];
      l++;
      flag = 1;
      continue;
    } else {
      b[r] = a[i];
      r--;
      flag = 0;
    }
  }
  for (int i = 1; i <= n; i++)
    cout << b[i] << ' ';
  cout << endl;
  return 0;
}
Problem p03675 (C++)

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

deque<int> x;

const int Q = 100007;

int v[Q];

int main() {
  // freopen("data.in","r",stdin);
  int dir = 1;

  int n;
  cin >> n;

  int r;

  for (int i = 1; i <= n; i++) {
    cin >> r;
    if (dir == 1) {
      x.push_back(r);
      dir = 2;
    } else {
      x.push_front(r);
      dir = 1;
    }
  }

  for (auto it : x) {
    v[++v[0]] = it;
  }

  if (dir == 1) {
    for (int i = 1; i <= n; i++) {
      cout << v[i] << " ";
    }
  } else {
    for (int i = n; i > 0; i--) {
      cout << v[i] << " ";
    }
  }
}

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

deque<int> x;

const int Q = 300007;

int v[Q];

int main() {
  // freopen("data.in","r",stdin);
  int dir = 1;

  int n;
  cin >> n;

  int r;

  for (int i = 1; i <= n; i++) {
    cin >> r;
    if (dir == 1) {
      x.push_back(r);
      dir = 2;
    } else {
      x.push_front(r);
      dir = 1;
    }
  }

  for (auto it : x) {
    v[++v[0]] = it;
  }

  if (dir == 1) {
    for (int i = 1; i <= n; i++) {
      cout << v[i] << " ";
    }
  } else {
    for (int i = n; i > 0; i--) {
      cout << v[i] << " ";
    }
  }
}
Problem p03675 (C++)

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

int main() {
  int n, a[22222], b[22222], i;
  cin >> n;
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  int evens, odds;

  if (1 & n) {
    evens = n / 2 + 2;
    odds = n / 2 + 1;
  } else {
    evens = n / 2;
    odds = n / 2 + 1;
  }

  for (i = 1; i <= n; ++i) {
    if (i & 1) {
      b[odds] = a[i];
      if (1 & n)
        odds--;
      else
        odds++;
    } else {
      b[evens] = a[i];
      if (1 & n)
        evens++;
      else
        evens--;
    }
  }
  for (i = 1; i <= n; ++i)
    cout << b[i] << " ";
  return 0;
}


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

int main() {
  int n, a[222222], b[222222], i;
  cin >> n;
  for (i = 1; i <= n; ++i)
    cin >> a[i];
  int evens, odds;

  if (1 & n) {
    evens = n / 2 + 2;
    odds = n / 2 + 1;
  } else {
    evens = n / 2;
    odds = n / 2 + 1;
  }

  for (i = 1; i <= n; ++i) {
    if (i & 1) {
      b[odds] = a[i];
      if (1 & n)
        odds--;
      else
        odds++;
    } else {
      b[evens] = a[i];
      if (1 & n)
        evens++;
      else
        evens--;
    }
  }
  for (i = 1; i <= n; ++i)
    cout << b[i] << " ";
  return 0;
}