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

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep3(i, n) for (int i = 0; i <= (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll2(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define REPLL(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define INF (int)1e9  //
#define LINF (ll)4e18 //
#define MOD (1e9) + 7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define PI 3.1415926535898

//------------------------------------------------------

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

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

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep3(i, n) for (int i = 0; i <= (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll2(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define REPLL(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define INF (int)1e9  //
#define LINF (ll)4e18 //
#define MOD (1e9) + 7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define PI 3.1415926535898

//------------------------------------------------------

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

  if (n == 1) {
    cout << a[0] << endl;
    return 0;
  }

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

  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;

int main() {
  int n, a[Nmax] = {}, b[Nmax] = {};
  cin >> n;
  REP(i, n) {
    cin >> b[i];
    reverse(b, b + i + 1);
  }
  REP(i, n) cout << b[i] << " ";
  cout << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;

int main() {
  int n, a[Nmax] = {}, b[Nmax] = {};
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    // reverse(b, b+i+1);
  }
  int j = n - 1, k = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0)
      b[k++] = a[n - i - 1];
    else
      b[j--] = a[n - i - 1];
  }
  REP(i, n) cout << b[i] << " ";
  cout << endl;
  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  vector<ll> b;

  REP(i, n) {
    b.pb(a[i]);
    reverse(b.begin(), b.end());
  }

  REP(i, n) cout << b[i] << " ";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  vector<ll> b;
  ll h = n / 2;
  if (n % 2) {
    REPR(i, h + 1) b.pb(a[2 * i]);
    REP(i, h) b.pb(a[2 * i + 1]);
  } else {
    REPR(i, h) b.pb(a[2 * i + 1]);
    REP(i, h) b.pb(a[2 * i]);
  }

  REP(i, n) cout << b[i] << " ";

  return 0;
}
Problem p03673 (Python)

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


def main():
    n = int(input())
    v = input().split("")
    print(pp(n, v))


def pp(n: int, v: List[str]) -> List[str]:
    x = []
    y = deque([])

    if n % 2 == 0:
        for i in range(n):
            if i % 2 == 0:
                y.append(v[i])
            else:
                x.append(v[i])
    else:
        for i in range(n):
            if i % 2 == 0:
                x.append(v[i])
            else:
                y.append(v[i])

    ret = []
    for i in range(len(x)):
        ret.append(x.pop())

    for i in range(len(y)):
        ret.append(y.popleft())

    return ret


if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque
from typing import List


def main():
    n = int(input())
    v = input().split(" ")
    print(*pp(n, v))


def pp(n: int, v: List[str]) -> List[str]:
    x = []
    y = deque([])

    if n % 2 == 0:
        for i in range(n):
            if i % 2 == 0:
                y.append(v[i])
            else:
                x.append(v[i])
    else:
        for i in range(n):
            if i % 2 == 0:
                x.append(v[i])
            else:
                y.append(v[i])

    ret = []
    for i in range(len(x)):
        ret.append(x.pop())

    for i in range(len(y)):
        ret.append(y.popleft())

    return ret


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

Buggy submission (status: Time Limit Exceeded):
int_n = int(input())
ar_int_a = list(map(int, input().split()))
ar_int_b = list()
for i in ar_int_a:
    ar_int_b.append(i)
    ar_int_b = ar_int_b[::-1]

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


Fixed submission:
int_n = int(input())
ar_int_a = list(map(int, input().split()))
ar_int_b = [-1] * int_n


idx = int_n // 2
ar_int_b[idx] = ar_int_a[0]

if int_n % 2 == 0:
    # 偶数
    for i in range(1, int_n):
        if i % 2 == 0:
            idx = idx + i
        else:
            idx = idx + (-1 * i)
        ar_int_b[idx] = ar_int_a[i]
else:
    # 奇数
    for i in range(1, int_n):
        if i % 2 == 0:
            idx = idx + (-1 * i)
        else:
            idx = idx + i
        ar_int_b[idx] = ar_int_a[i]


print(" ".join(map(str, ar_int_b)))
Problem p03673 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    n = int(input())
    A = input().split()
    ans = []
    if n % 2 == 0:
        for i in range(0, n - 1, 2):
            ans.append(A[i])
            ans = [A[i + 1]] + ans
    else:
        for i in range(0, n - 1, 2):
            ans.append(A[i + 1])
            ans = [A[i]] + ans
        ans = [A[-1]] + ans
    print(" ".join(ans))


main()


Fixed submission:
def main():
    n = int(input())
    A = input().split()
    B = [0] * n
    k = n % 2
    l = n // 2
    if k == 0:
        l -= 1
    r = l + 1
    for i in range(n):
        if i % 2 != k:
            B[l] = A[i]
            l -= 1
        else:
            B[r] = A[i]
            r += 1
    print(" ".join(B))


main()
Problem p03673 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import deque


def solve(a):
    ans = deque()

    for i, aa in enumerate(a):
        ans.append(str(aa))
        ans.reverse()

    return list(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(" ".join(solve(a)))


Fixed submission:
from collections import deque


def solve(a):
    ans = deque()

    for i, aa in enumerate(a):
        if i % 2 == 0:
            ans.append(str(aa))
        else:
            ans.appendleft(str(aa))

    if len(a) % 2 == 1:
        ans.reverse()

    return list(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    print(" ".join(solve(a)))
Problem p03673 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
alist = list(map(int, input().split()))
b = []
for i in range(n):
    b.append(alist[i])
    b = b[::-1]

for _ in b:
    print(_, end=" ")


Fixed submission:
n = int(input())
alist = list(map(int, input().split()))
b = alist[::-2] + alist[n % 2 :: 2]
print(" ".join(list(map(str, b))))
Problem p03673 (Python)

Buggy submission (status: Time Limit Exceeded):
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
b = deque()

for _ in range(n):
    b.append(a.popleft())
    b.reverse()

print(*b)


Fixed submission:
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
b = deque()

if n % 2 == 1:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())

print(*b)
Problem p03673 (C++)

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

using namespace std;

#define N 100008

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

void solve() {
  int len = 0;
  for (int i = n; i >= 1; i -= 2)
    b[++len] = a[i];
  for (int i = n - 1, len = n; i >= 1; i -= 2)
    b[len--] = a[i];
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  printf("\n");
}

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

int main() {
  init();
  solve();
  return 0;
}

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

using namespace std;

#define N 200008

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

void solve() {
  int len = 0;
  for (int i = n; i >= 1; i -= 2)
    b[++len] = a[i];
  for (int i = n - 1, len = n; i >= 1; i -= 2)
    b[len--] = a[i];
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  printf("\n");
}

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

int main() {
  init();
  solve();
  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (a); i > (n); i--)
#define lep(i, a, n) for (ll i = (a); i <= (n); i++)
#define pel(i, a, n) for (ll i = (a); i >= (n); i--)
#define clr(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9 + 7;
ll n, m, l;
string s, t;
ll d[200010], dp[500][500];

int main() {
  cin >> n;
  rep(i, 0, n) cin >> d[i];
  ll ans[200010];
  clr(ans, 0);
  l = 200005;
  m = l + 1;
  rep(i, 0, n) {
    if (i % 2 == (n - 1) % 2)
      ans[l--] = d[i];
    else
      ans[m++] = d[i];
  }
  rep(i, l + 1, m) cout << ans[i] << " ";
  puts("");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (a); i > (n); i--)
#define lep(i, a, n) for (ll i = (a); i <= (n); i++)
#define pel(i, a, n) for (ll i = (a); i >= (n); i--)
#define clr(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9 + 7;
ll n, m, l;
string s, t;
ll d[200010], dp[500][500];

int main() {
  cin >> n;
  rep(i, 0, n) cin >> d[i];
  ll ans[200010];
  clr(ans, 0);
  l = 100005;
  m = l + 1;
  rep(i, 0, n) {
    if (i % 2 == (n - 1) % 2)
      ans[l--] = d[i];
    else
      ans[m++] = d[i];
  }
  rep(i, l + 1, m) cout << ans[i] << " ";
  puts("");
  return 0;
}
Problem p03673 (C++)

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

int main() {
  int n;
  cin >> n;
  deque<ll> v;
  ll a;
  cin >> a;
  v.push_back(a);

  int b = -1;
  for (int i = 1; i < n; i++) {
    cin >> a;
    b = b * (-1);
    if (b == 1) {
      v.push_front(a);
    } else {
      v.push_back(a);
    }
  }

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

  return 0;
}

Fixed submission:
#include <deque>
#include <iostream>
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  deque<ll> v;
  ll a;
  cin >> a;
  v.push_back(a);

  int b = -1;
  for (int i = 1; i < n; i++) {
    cin >> a;
    b = b * (-1);
    if (b == 1) {
      v.push_front(a);
    } else {
      v.push_back(a);
    }
  }

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

  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCm(ll n, ll m) {
  if (m == 0 || m == n) {
    return 1;
  } else if (m == 1) {
    return n;
  }
  return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

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

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

Fixed submission:
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll nCm(ll n, ll m) {
  if (m == 0 || m == n) {
    return 1;
  } else if (m == 1) {
    return n;
  }
  return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

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

  vector<int> b;

  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        b.push_back(a[i]);
      } else {
        b.insert(b.begin(), a[i]);
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        b.insert(b.begin(), a[i]);
      } else {
        b.push_back(a[i]);
      }
    }
  }
  for (int i = 0; i < b.size(); i++) {
    if (i != b.size() - 1) {
      cout << b[i] << " ";
    } else {
      cout << b[i] << endl;
    }
  }
}
Problem p03673 (C++)

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s > 0; s--)

int main() {
  ll n;
  cin >> n;
  vecll a(n);
  bool beforespace = false;
  forll(i, 0, n) cin >> a[i];

  forll(i, 0, n / 2) {
    beforespace = true;
    cout << a[n - 1 - i * 2] << " ";
  }
  forll(i, 0, n / 2) {
    if (beforespace) {
      beforespace = false;
      cout << a[i * 2];
    } else
      cout << " " << a[i * 2];
  }
  if (n % 2 == 1) {
    if (beforespace)
      cout << a[n / 2 + 1];
    else
      cout << " " << a[n / 2 + 1];
  }
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s > 0; s--)

int main() {
  ll n;
  cin >> n;
  vecll a(n);
  bool beforespace = false;
  forll(i, 0, n) cin >> a[i];

  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] << " ";
    }
    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] << " ";
    }
    cout << endl;
  }
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define erep(i, n) for (int i = 0; i <= n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define erep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000
#define INF 100000000000000

ll gcm(ll a, ll b);
ll lcm(ll a, ll b);

int main() {
  int n;
  cin >> n;
  vint ans(0);
  rep(i, n) {
    int a;
    cin >> a;
    ans.push_back(a);
    reverse(ans.begin(), ans.end());
  }
  rep(i, n) cout << ans[i] << " ";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define erep(i, n) for (int i = 0; i <= n; i++)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define erep1(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000
#define INF 100000000000000

ll gcm(ll a, ll b);
ll lcm(ll a, ll b);

int main() {
  int n;
  cin >> n;
  vint A(n);
  vint ans(n);
  int key = 0;
  rep(i, n) cin >> A[i];
  if (n % 2 == 0) {
    for (int i = n - 1; i >= 1; i -= 2) {
      ans[key] = A[i];
      key++;
    }
    for (int i = 0; i < n - 1; i += 2) {
      ans[key] = A[i];
      key++;
    }
  } else {
    for (int i = n - 1; i >= 0; i -= 2) {
      ans[key] = A[i];
      key++;
    }
    for (int i = 1; i <= n - 1; i += 2) {
      ans[key] = A[i];
      key++;
    }
  }
  rep(i, n) cout << ans[i] << " ";
}
Problem p03673 (C++)

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

#define ll long long
#define maxn 20000

int main() {
  int n, st, dr, l = 0;
  scanf("%d", &n);
  ll a[maxn + 1];
  int i = n / 2 + 1;
  st = i - 1;
  dr = i + 1;
  scanf("%lld", &a[i]);
  if (n % 2 != 0)
    l = 1;
  for (int j = 2; j <= n; j++) {
    if (l == 0) {
      scanf("%lld", &a[st]);
      st--;
    } else {
      scanf("%lld", &a[dr]);
      dr++;
    }
    l = 1 - l;
  }

  for (int i = 1; i <= n; i++)
    printf("%lld ", a[i]);
  return 0;
}


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

#define ll long long
#define maxn 200000

int main() {
  int n, st, dr, l = 0;
  scanf("%d", &n);
  ll a[maxn + 1];
  int i = n / 2 + 1;
  st = i - 1;
  dr = i + 1;
  scanf("%lld", &a[i]);
  if (n % 2 != 0)
    l = 1;
  for (int j = 2; j <= n; j++) {
    if (l == 0) {
      scanf("%lld", &a[st]);
      st--;
    } else {
      scanf("%lld", &a[dr]);
      dr++;
    }
    l = 1 - l;
  }

  for (int i = 1; i <= n; i++)
    printf("%lld ", a[i]);
  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }
  vector<int> res;
  for (int i = 0; i < n; i++) {
    res.push_back(ans[i]);
    reverse(res.begin(), res.end());
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
}

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

int main() {
  int n = 0;
  cin >> n;
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }
  vector<int> res(n, 0);
  int index = 0;
  for (int i = n - 1; i >= 0; i -= 2) {
    res[index] = ans[i];
    if (i - 1 >= 0) {
      res[n - 1 - index] = ans[i - 1];
    }
    index += 1;
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << " ";
  }
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>
#include <vector>

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

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  int z = x % y;
  if (z == 0) {
    return y;
  } else {
    return gcd(y, z);
  }
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

void solve() {
  int n;
  cin >> n;
  ll a[n];
  vector<ll> b;
  REP(i, n) cin >> a[i];

  REP(i, n) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }
  for (auto i = b.begin(); i != b.end(); i++) {
    cout << *i << " ";
  }
  cout << endl;
}

int main() {
  solve();
  return 0;
}

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

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

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

int gcd(int a, int b) {
  int x = max(a, b);
  int y = min(a, b);
  int z = x % y;
  if (z == 0) {
    return y;
  } else {
    return gcd(y, z);
  }
}

int lcm(int a, int b) { return (a * b) / gcd(a, b); }

void solve() {
  int n;
  cin >> n;
  ll a[n];
  vector<ll> b;
  REP(i, n) cin >> a[i];

  for (int i = n - 1; i >= 0; i -= 2) {
    if (i >= 0 && i < n) {
      b.push_back(a[i]);
    }
  }
  for (int i = n % 2; i < n; i += 2) {
    if (i >= 0 && i < n) {
      b.push_back(a[i]);
    }
  }
  for (auto i = b.begin(); i != b.end(); i++) {
    cout << *i << " ";
  }
  cout << endl;
}

int main() {
  solve();
  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ans;
  rep(i, n) { cin >> a.at(i); }
  list<int> b;
  for (int i = 0; i < n; i += 2) {
    b.PB(a.at(i));
    b.PF(a.at(i + 1));
  }
  for (auto i = b.begin(); i != b.end(); i++) {
    cout << *(i) << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ans;
  rep(i, n) { cin >> a.at(i); }
  list<int> b;
  if (n % 2 == 0) {
    for (int i = 0; i < n - 1; i += 2) {
      b.PB(a.at(i));
      b.PF(a.at(i + 1));
    }
  }
  if (n % 2 == 1) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        b.PF(a.at(i));
      } else {
        b.PB(a.at(i));
      }
    }
  }
  for (auto i = b.begin(); i != b.end(); i++) {
    cout << *(i) << " ";
  }
  cout << endl;
}
Problem p03673 (C++)

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

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

  vector<lint> b;
  for (lint i = 0; i < n; i++) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }

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

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

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

  vector<lint> b(n);

  lint i = 0;
  for (i = 0; i < (n + 1) / 2; i++) {
    b[i] = a[n - 2 * i - 1];
  }
  for (i = 0; i < (n + 1) / 2; i++) {
    b[i + (n + 1) / 2] = a[2 * i + n % 2];
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int a[1000560];
int main() {
  int n;
  while (scanf("%d", &n)) {
    int t;
    for (int i = 1; i <= n; i++)
      scanf("%d", &a[i]);
    if (n % 2 == 1) {
      for (int i = n; i >= 1; i -= 2)
        printf("%d ", a[i]);
      for (int i = 2; i <= n - 1; i += 2) {
        if (i == n - 1)
          printf("%d", a[i]);
        else
          printf("%d ", a[i]);
      }
    } else if (n % 2 == 0) {
      for (int i = n; i > 0; i -= 2)
        printf("%d ", a[i]);
      for (int i = 1; i <= n - 1; i += 2) {
        if (i == n - 1)
          printf("%d", a[i]);
        else
          printf("%d ", a[i]);
      }
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int a[1000560];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    int t;
    for (int i = 1; i <= n; i++)
      scanf("%d", &a[i]);
    if (n % 2 == 1) {
      for (int i = n; i >= 1; i -= 2)
        printf("%d ", a[i]);
      for (int i = 2; i <= n - 1; i += 2) {
        if (i == n - 1)
          printf("%d", a[i]);
        else
          printf("%d ", a[i]);
      }
    } else if (n % 2 == 0) {
      for (int i = n; i > 0; i -= 2)
        printf("%d ", a[i]);
      for (int i = 1; i <= n - 1; i += 2) {
        if (i == n - 1)
          printf("%d", a[i]);
        else
          printf("%d ", a[i]);
      }
    }
    printf("\n");
  }
  return 0;
}
Problem p03673 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  vector<int> b;
  for (int i = 0; i < n; i++) {
    b.push_back(v.at(i));
    reverse(b.begin(), b.end());
  }
  for (int i = 0; i < n; i++) {
    cout << b.at(i) << " ";
  }
  cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }

  vector<int> b(n);
  int t = 0;
  int j = 0, k = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (t % 2 == 0) {
      b.at(j) = v.at(i);
      j++;
    } else {
      b.at(k) = v.at(i);
      k--;
    }
    t++;
  }
  for (int i = 0; i < n; i++) {
    cout << b.at(i) << " ";
  }
  cout << endl;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  deque<int> q;
  rep(i, n) {
    cin >> a[i];
    q.push_back(a[i]);
    reverse(q.begin(), q.end());
  }
  for (int x : q) {
    cout << x << " ";
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  deque<int> q;
  rep(i, n) {
    cin >> a[i];
    if (n % 2 == i % 2) {
      q.push_back(a[i]);
    } else {
      q.push_front(a[i]);
    }
  }
  for (int x : q) {
    cout << x << " ";
  }
}
Problem p03673 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int rev[100005], n, a[100005];
int main() {
  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; i += 2) {
      cout << a[i] << " ";
    }
  } else {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << " ";
    }
    for (int i = 1; i <= n; i += 2) {
      cout << a[i] << " ";
    }
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
int main() {
  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; i += 2) {
      cout << a[i] << " ";
    }
  } else {
    for (int i = n; i >= 1; i -= 2) {
      cout << a[i] << " ";
    }
    for (int i = 1; i <= n; i += 2) {
      cout << a[i] << " ";
    }
  }
  cout << endl;
  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

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

  vi b;
  rep(i, n) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }

  rep(i, n - 1) { cout << b[i] << ' '; }
  cout << b[n - 1] << '\n';
}

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

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

  vi b;
  rep(i, n) {
    if (i + 1 <= (n + 1) / 2) {
      b.push_back(a[n - 2 * i - 1]);
    } else {
      b.push_back(a[n - 2 * (n - i)]);
    }
  }

  rep(i, n - 1) { cout << b[i] << ' '; }
  cout << b[n - 1] << '\n';
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  vector<int> b(0);
  for (int i = 0; i < n; i++) {
    b.push_back(a.at(i));
    reverse(b.begin(), b.end());
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cout << b.at(i) << endl;
    else
      cout << b.at(i) << ' ';
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  deque<int> b;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 1)
        b.push_front(a.at(i));
      else
        b.push_back(a.at(i));
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0)
        b.push_front(a.at(i));
      else
        b.push_back(a.at(i));
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cout << b.at(i) << endl;
    else
      cout << b.at(i) << ' ';
  }
}
Problem p03673 (C++)

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

long long a[100005], b[100005];

int main() {
  long long n, flag = 0, l, r;
  scanf("%lld", &n);
  r = n;
  l = 1;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = n; i >= 1; i = i - 2)
    b[l++] = a[i];
  for (int i = n - 1; i >= 1; i = i - 2)
    b[r--] = a[i];
  for (int i = 1; i <= n; i++) {
    printf("%lld ", b[i]);
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
using namespace std;

long long a[200005], b[200005];

int main() {
  long long n, flag = 0, l, r;
  scanf("%lld", &n);
  r = n;
  l = 1;
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (int i = n; i >= 1; i = i - 2)
    b[l++] = a[i];
  for (int i = n - 1; i >= 1; i = i - 2)
    b[r--] = a[i];
  for (int i = 1; i <= n; i++) {
    printf("%lld ", b[i]);
  }
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> ans;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    ans.push_back(a);
    reverse(ans.begin(), ans.end());
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  deque<ll> ans;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      ll t;
      cin >> t;
      if ((i + 1) % 2 == 0) {
        ans.push_front(t);
      } else {
        ans.push_back(t);
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      ll t;
      cin >> t;
      if ((i + 1) % 2 == 0) {
        ans.push_back(t);
      } else {
        ans.push_front(t);
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p03673 (C++)

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

using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl

#define uni(x) x.erase(unique(all(x)), x.end())
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX / 3
#define MAX_N 1000
#define M_INF 1000000000
int n, m, v, i, j;
void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll a[20005];
  ll b[20005];
  ll k, l;
  rep(i, n) cin >> a[i];
  for (j = n; j > 0; j--) {
    if (abs(n - j) % 2 == 0) {
      k = 0;
      k += abs(n - j) / 2;
    } else {
      k = n - 1;
      k -= abs(n - j) / 2;
    }
    b[k] = a[j - 1];
  }
  rep(i, n) {
    if (i != n - 1) {
      cout << b[i] << " ";
    } else {
      cout << b[i] << endl;
    }
  }
}

int main() {
  solve();
  return 0;
}


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

using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl

#define uni(x) x.erase(unique(all(x)), x.end())
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX / 3
#define MAX_N 1000
#define M_INF 1000000000
int n, m, v, i, j;
void solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll a[200005];
  ll b[200005];
  ll k, l;
  rep(i, n) cin >> a[i];
  for (j = n; j > 0; j--) {
    if (abs(n - j) % 2 == 0) {
      k = 0;
      k += abs(n - j) / 2;
    } else {
      k = n - 1;
      k -= abs(n - j) / 2;
    }
    b[k] = a[j - 1];
  }
  rep(i, n) {
    if (i != n - 1) {
      cout << b[i] << " ";
    } else {
      cout << b[i] << endl;
    }
  }
}

int main() {
  solve();
  return 0;
}
Problem p03673 (C++)

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

#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define ces(d) cout << " " << endl;

int main() {

  int N;
  vector<long long> A(100001);
  vector<long long> B;
  cin >> N;
  fx(N) { cin >> A.at(x + 1); }

  int k = N;

  while (k > 1) {
    cout << A.at(k);
    cout << " ";
    k -= 2;
  }
  k = 1;
  while (k < N - 1) {
    cout << A.at(k);
    cout << " ";
    if (N % 2 == 1 && k == 1) {
      k += 1;
    } else {
      k += 2;
    }
  }

  if (N == 1) {
    cout << A.at(N);
  } else {
    cout << A.at(N - 1);
  }
}

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

#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define ces(d) cout << " " << endl;

int main() {

  int N;
  vector<long long> A(1000001);
  vector<long long> B;
  cin >> N;
  fx(N) { cin >> A.at(x + 1); }

  int k = N;

  while (k > 1) {
    cout << A.at(k);
    cout << " ";
    k -= 2;
  }
  k = 1;
  while (k < N - 1) {
    cout << A.at(k);
    cout << " ";
    if (N % 2 == 1 && k == 1) {
      k += 1;
    } else {
      k += 2;
    }
  }

  if (N == 1) {
    cout << A.at(N);
  } else {
    cout << A.at(N - 1);
  }
}
Problem p03673 (C++)

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

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

  list<int> b;
  for (int i = 0; i < n; i++) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }
  for (auto x : b) {
    cout << x << " ";
  }
  cout << endl;

  return 0;
}

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

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

  list<int> b;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0)
        b.push_back(a[i]);
      else
        b.push_front(a[i]);
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0)
        b.push_front(a[i]);
      else
        b.push_back(a[i]);
    }
  }
  for (auto x : b) {
    cout << x << " ";
  }
  cout << endl;

  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b;
  rep(i, n) cin >> a[i];

  rep(i, n) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }

  for (auto c : b) {
    printf("%d ", c);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b;
  rep(i, n) cin >> a[i];

  rep(i, n) {
    if (n % 2) {
      if (i % 2) {
        b.push_back(a[i]);
      } else {
        b.insert(b.begin(), a[i]);
      }
    } else {
      if (i % 2) {
        b.insert(b.begin(), a[i]);
      } else {
        b.push_back(a[i]);
      }
    }
  }

  for (auto c : b) {
    printf("%d ", c);
  }
  return 0;
}
Problem p03673 (Python)

Buggy submission (status: Runtime Error):
import collections

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

flag = True

for x in a:
    if flag:
        b.append(x)
        flag = False
    else:
        b.appendleft(x)
        flag = True
if flag:
    print(*b)
else:
    print(*b[::-1])


Fixed submission:
import collections

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

flag = True

for x in a:
    if flag:
        b.append(x)
        flag = False
    else:
        b.appendleft(x)
        flag = True
if flag:
    print(*b)
else:
    print(*list(b)[::-1])
Problem p03674 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (N + 2)
fi = [1] * (N + 2)
for i in range(2, N + 2):
    f[i] = i * f[i - 1]
    f[i] %= mod
for i in range(2, N + 2):
    fi[i] = fi[i - 1] * pow(i, mod - 2, mod)
    fi[i] %= mod


def comb(n, r):
    if 0 <= n and 0 <= r and 0 <= n - r:
        return (f[n] * fi[r] * fi[n - r]) % mod
    else:
        return 0


b = set()
for a in A:
    if a in b:
        break
    b.add(a)
c = []
for i in range(N):
    if A[i] == a:
        c += [i]
i, j = c
for x in range(1, N + 2):
    print((comb(N + 1, x) - (comb(N - j + i, x - 1))) % mod)


Fixed submission:
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (N + 2)
fi = [1] * (N + 2)
for i in range(2, N + 2):
    f[i] = i * f[i - 1]
    f[i] %= mod
for i in range(2, N + 2):
    fi[i] = fi[i - 1] * pow(i, mod - 2, mod)
    fi[i] %= mod


def comb(n, r):
    if 0 <= n and 0 <= r and 0 <= n - r:
        return (f[n] * fi[r] * fi[n - r]) % mod
    else:
        return 0


b = set()
for a in A:
    if a in b:
        break
    b.add(a)
c = []
for i in range(N + 1):
    if A[i] == a:
        c += [i]
i, j = c
for x in range(1, N + 2):
    print((comb(N + 1, x) - (comb(N - j + i, x - 1))) % mod)
Problem p03674 (Python)

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

dup = sum(a) - n * (n + 1) // 2
d1 = a.index(dup)
d2 = a.index(dup, d1 + 1)

C = n + 1
Cdup = 1
for k in range(1, n + 2):
    print((C - Cdup) % (10**9 + 7))
    C = C * (n + 1 - k) // (k + 1)
    Cdup = Cdup * (d1 + n - d2 - k + 1) // k


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

dup = sum(a) - n * (n + 1) // 2
d1 = a.index(dup)
d2 = a.index(dup, d1 + 1)

N = n + 1
Ndup = d1 + n - d2

MOD = 10**9 + 7


def power(x, n):
    ans = 1
    while n:
        if n % 2 == 1:
            ans = (ans * x) % MOD
        x = (x * x) % MOD
        n //= 2
    return ans


# fack[k]: kの階乗
fact = [0 for i in range(N + 1)]
fact[0] = 1
for i in range(1, N + 1):
    fact[i] = (fact[i - 1] * i) % MOD

# inv[k]: kの階乗の逆元
inv = [0 for i in range(N + 1)]
inv[N] = power(fact[N], MOD - 2) % MOD
for i in range(N - 1, -1, -1):
    inv[i] = (inv[i + 1] * (i + 1)) % MOD


def comb(n, r):
    if n < r:
        return 0
    else:
        return (fact[n] * inv[n - r] * inv[r]) % MOD


for k in range(1, N + 1):
    C = comb(N, k)
    Cdup = comb(Ndup, k - 1)
    print((C - Cdup) % MOD)