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

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

using namespace std;

int F[22][1 << 19], K[22][1 << 19], n, m, k, S[22][22];

void add(int &x, int y) { x = (x + y) % P; }

int main() {
  memset(S, -1, sizeof S), scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z), S[--x][--y] = z;
  }
  for (int i = 0; i < (1 << n - 1); i++)
    for (int lst = -1, j = n - 2; j >= 0; j--) {
      if ((i >> j) & 1)
        lst = j;
      K[j][i] = i + (1 << j) - (1 << lst);
    }
  F[0][0] = 1;
  for (int O = 0; O < m; O++, memcpy(F[0], F[n - 1], sizeof F[0]))
    for (int T = 0; T < n - 1; T++) {
      memset(F[T + 1], 0, sizeof F[T + 1]);
      for (int i = 0; i < (1 << n - 1); i++) {
        if (S[O][T] != 1 && !((i >> T) & 1))
          add(F[T + 1][i], F[T][i]);
        if (S[O][T] != 0)
          add(F[T + 1][K[T][i]], F[T][i]);
      }
    }
  int ans = 0;
  for (int i = 0; i < (1 << n - 1); i++)
    add(ans, F[n - 1][i]);
  return printf("%d\n", ans), 0;
}

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

using namespace std;

int F[22][1 << 19], K[22][1 << 19], n, m, k, S[22][22];

void add(int &x, int y) { x = (x + y) % P; }

int main() {
  memset(S, -1, sizeof S), scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z), S[--x][--y] = z;
  }
  for (int i = 0; i < (1 << n - 1); i++)
    for (int lst = -1, j = n - 2; j >= 0; j--) {
      if ((i >> j) & 1)
        lst = j;
      K[j][i] = i + (1 << j) - (lst != -1 ? 1 << lst : 0);
    }
  F[0][0] = 1;
  for (int O = 0; O < m; O++, memcpy(F[0], F[n - 1], sizeof F[0]))
    for (int T = 0; T < n - 1; T++) {
      memset(F[T + 1], 0, sizeof F[T + 1]);
      for (int i = 0; i < (1 << n - 1); i++) {
        if (S[O][T] != 1 && !((i >> T) & 1))
          add(F[T + 1][i], F[T][i]);
        if (S[O][T] != 0)
          add(F[T + 1][K[T][i]], F[T][i]);
      }
    }
  int ans = 0;
  for (int i = 0; i < (1 << n - 1); i++)
    add(ans, F[n - 1][i]);
  return printf("%d\n", ans), 0;
}
Problem p03670 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int f[2][22][600005], n, m, K, S[600005], st[600005], bin[32],
    nxt[600005][22][2];
void add(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }
int main() {
  scanf("%d%d%d", &n, &m, &K);
  n--;
  bin[0] = 1;
  for (int i = 1; i <= 30; i++)
    bin[i] = bin[i - 1] * 2;
  for (int i = 0; i < (1 << n); i++) {
    int pos[2] = {0, 0};
    for (int p = n; ~p; p--) {
      nxt[i][p][0] = pos[0];
      nxt[i][p][1] = pos[1];
      pos[(i >> p - 1) & 1] = p;
    }
  }
  for (int i = 1, a, b, c; i <= K; i++) {
    scanf("%d%d%d", &a, &b, &c);
    S[a] |= (1 << b - 1);
    if (c)
      st[a] |= (1 << b - 1);
  }
  int pre = 0, now = 1;
  f[1][0][0] = 1;
  for (int i = 1; i <= m; i++) {
    memset(f[pre], 0, sizeof(f[pre]));
    for (int p = 0; p < n; p++) {
      for (int j = 0; j < (1 << n); j++)
        if (f[now][p][j]) {
          int pos = nxt[j][p][0], pp = nxt[j][pos][1];
          add(f[now][p + 1][j], f[now][p][j]);
          if (pos == p + 1)
            add(f[now][pos][j ^ (1 << pos - 1) ^ (1 << pp - 1)], f[now][p][j]);
        }
    }
    for (int j = 0; j < (1 << n); j++) {
      if ((j & S[i]) != st[i]) {
        f[now][n][j] = 0;
        continue;
      }
      add(f[pre][0][j], f[now][n][j]);
    }
    swap(now, pre);
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++)
    add(ans, f[now][0][i]);
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int f[2][22][600005], n, m, K, S[600005], st[600005], bin[32],
    nxt[600005][22][2];
void add(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }
int main() {
  scanf("%d%d%d", &n, &m, &K);
  n--;
  bin[0] = 1;
  for (int i = 1; i <= 30; i++)
    bin[i] = bin[i - 1] * 2;
  for (int i = 0; i < (1 << n); i++) {
    int pos[2] = {0, 0};
    for (int p = n; ~p; p--) {
      nxt[i][p][0] = pos[0];
      nxt[i][p][1] = pos[1];
      pos[(i >> p - 1) & 1] = p;
    }
  }
  for (int i = 1, a, b, c; i <= K; i++) {
    scanf("%d%d%d", &a, &b, &c);
    S[a] |= (1 << b - 1);
    if (c)
      st[a] |= (1 << b - 1);
  }
  int pre = 0, now = 1;
  f[1][0][0] = 1;
  for (int i = 1; i <= m; i++) {
    memset(f[pre], 0, sizeof(f[pre]));
    for (int p = 0; p < n; p++) {
      for (int j = 0; j < (1 << n); j++)
        if (f[now][p][j]) {
          int pos = nxt[j][p][0], pp = nxt[j][pos][1];
          add(f[now][p + 1][j], f[now][p][j]);
          if (pos == p + 1)
            add(f[now][pos][j ^ (1 << pos - 1) ^ (pp ? (1 << pp - 1) : 0)],
                f[now][p][j]);
        }
    }
    for (int j = 0; j < (1 << n); j++) {
      if ((j & S[i]) != st[i]) {
        f[now][n][j] = 0;
        continue;
      }
      add(f[pre][0][j], f[now][n][j]);
    }
    swap(now, pre);
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++)
    add(ans, f[now][0][i]);
  printf("%d", ans);
  return 0;
}
Problem p03670 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>
#include <cstring>
const int mod = 1000000007;
inline void add(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
int p[30], q[30], go[1 << 21][30], put[1 << 21], f[1 << 21], n, m, k;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  while (k--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    p[a] |= 1 << b;
    q[a] |= c << b;
  }
  n--;
  memset(go, -1, sizeof go);
  for (int t = 0; t < (1 << n); t++) {
    int id = 0;
    for (int i = 0; i < n; i++)
      if (t & (1 << i)) {
        if (i && !(t & (1 << (i - 1))))
          go[t][id] = t ^ (1 << i) ^ (1 << (i - 1));
        id++;
      }
  }
  memset(put, -1, sizeof put);
  for (int t = 0; t < (1 << n); t++)
    for (int i = n - 1; i >= 0; i--)
      if (!(t & (1 << i))) {
        put[t] = t ^ (1 << i);
        break;
      }
  f[0] = 1;
  for (int i = 0; i < m; i++) {
    for (int t = 0; t < (1 << n) - 1; t++)
      add(f[put[t]], f[t]);
    for (int j = 0; j < n; j++)
      for (int t = (1 << n) - 1; t >= 0; t--)
        if (go[t][j] != -1)
          add(f[go[t][j]], f[t]);
    for (int t = 0; t < (1 << n); t++)
      if ((t & p[i]) != q[i])
        f[t] = 0;
  }
  int ans = 0;
  for (int t = 0; t < (1 << n); t++)
    add(ans, f[t]);
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
const int mod = 1000000007;
inline void add(int &a, int b) {
  if ((a += b) >= mod)
    a -= mod;
}
int p[30], q[30], go[3 << 19][23], put[1 << 21], f[1 << 21], n, m, k;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  while (k--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    p[a] |= 1 << b;
    q[a] |= c << b;
  }
  n--;
  memset(go, -1, sizeof go);
  for (int t = 0; t < (1 << n); t++) {
    int id = 0;
    for (int i = 0; i < n; i++)
      if (t & (1 << i)) {
        if (i && !(t & (1 << (i - 1))))
          go[t][id] = t ^ (1 << i) ^ (1 << (i - 1));
        id++;
      }
  }
  memset(put, -1, sizeof put);
  for (int t = 0; t < (1 << n); t++)
    for (int i = n - 1; i >= 0; i--)
      if (!(t & (1 << i))) {
        put[t] = t ^ (1 << i);
        break;
      }
  f[0] = 1;
  for (int i = 0; i < m; i++) {
    for (int t = 0; t < (1 << n) - 1; t++)
      add(f[put[t]], f[t]);
    for (int j = 0; j < n; j++)
      for (int t = (1 << n) - 1; t >= 0; t--)
        if (go[t][j] != -1)
          add(f[go[t][j]], f[t]);
    for (int t = 0; t < (1 << n); t++)
      if ((t & p[i]) != q[i])
        f[t] = 0;
  }
  int ans = 0;
  for (int t = 0; t < (1 << n); t++)
    add(ans, f[t]);
  printf("%d\n", ans);
  return 0;
}
Problem p03670 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>
#include <vector>
using namespace std;

const int N = 1 << 25;
const int MOD = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  n--; // attention
  vector<vector<int>> check(m, vector<int>(n, -1));
  for (int i = 0; i < k; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    check[a][b] = c;
  }
  vector<vector<int>> dp(2, vector<int>(N, 0));
  dp[0][0] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int mask = 0; mask < (1 << n); mask++) {
        dp[1][mask] = 0;
      }
      for (int mask = 0; mask < (1 << n); mask++) {
        if (dp[0][mask] == 0)
          continue;
        // left
        if (check[i][j] != 1 && (~mask >> j) & 1) {
          add(dp[1][mask], dp[0][mask]);
        }
        // right
        if (check[i][j] != 0) {
          int mask2 = (((mask - (1 << j)) & mask) | (1 << j));
          add(dp[1][mask2], dp[0][mask]);
        }
      }
      swap(dp[0], dp[1]);
    }
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    add(ans, dp[0][mask]);
  }
  printf("%d\n", ans);
  return 0;
}


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

const int N = 1 << 19;
const int MOD = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  n--; // attention
  vector<vector<int>> check(m, vector<int>(n, -1));
  for (int i = 0; i < k; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    check[a][b] = c;
  }
  vector<vector<int>> dp(2, vector<int>(N, 0));
  dp[0][0] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      for (int mask = 0; mask < (1 << n); mask++) {
        dp[1][mask] = 0;
      }
      for (int mask = 0; mask < (1 << n); mask++) {
        if (dp[0][mask] == 0)
          continue;
        // left
        if (check[i][j] != 1 && (~mask >> j) & 1) {
          add(dp[1][mask], dp[0][mask]);
        }
        // right
        if (check[i][j] != 0) {
          int mask2 = (((mask - (1 << j)) & mask) | (1 << j));
          add(dp[1][mask2], dp[0][mask]);
        }
      }
      swap(dp[0], dp[1]);
    }
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    add(ans, dp[0][mask]);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03670 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 45, mod = 1e9 + 7;
int n, m, K, p[N][N], f[2][20][1 << 20], nxt[1 << 20][N];
inline void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}
int main() {
  cin >> n >> m >> K;
  int x, y, z, lim = (1 << n) - 1;
  n--;
  memset(p, -1, sizeof(p));
  for (int i = 1; i <= K; i++) {
    scanf("%d%d%d", &x, &y, &z);
    p[x][y] = z;
  }
  for (int i = 0; i <= lim; i++) {
    for (int j = 0; j < n; j++) {
      if (!(i >> j & 1)) {
        for (int k = j + 1; k < n; k++)
          if (i >> k & 1) {
            nxt[i][j] = i ^ (1 << k) ^ (1 << j);
            break;
          }
        if (!nxt[i][j])
          nxt[i][j] = i ^ (1 << j);
      }
    }
  }
  bool t = 0;
  f[t ^ 1][n][0] = 1;
  for (int i = 1; i <= m; i++, t ^= 1) {
    for (int j = 0; j <= lim; j++)
      f[t][0][j] = f[t ^ 1][n][j], f[t ^ 1][n][j] = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k <= lim; k++) {
        if (!f[t][j][k])
          continue;
        if (p[i][j + 1] != (k >> j & 1 ^ 1))
          add(f[t][j + 1][k], f[t][j][k]);
        if (p[i][j + 1] && !(k >> j & 1))
          add(f[t][j + 1][nxt[k][j]], f[t][j][k]);
        f[t][j][k] = 0;
      }
    }
  }
  int ans = 0;
  t ^= 1;
  for (int i = 0; i <= lim; i++)
    add(ans, f[t][n][i]);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 45, mod = 1e9 + 7;
int n, m, K, p[N][N], f[2][20][1 << 20], nxt[1 << 20][20];
inline void add(int &x, int y) {
  x += y;
  if (x >= mod)
    x -= mod;
}
int main() {
  cin >> n >> m >> K;
  int x, y, z, lim = (1 << n) - 1;
  n--;
  memset(p, -1, sizeof(p));
  for (int i = 1; i <= K; i++) {
    scanf("%d%d%d", &x, &y, &z);
    p[x][y] = z;
  }
  for (int i = 0; i <= lim; i++) {
    for (int j = 0; j < n; j++) {
      if (!(i >> j & 1)) {
        for (int k = j + 1; k < n; k++)
          if (i >> k & 1) {
            nxt[i][j] = i ^ (1 << k) ^ (1 << j);
            break;
          }
        if (!nxt[i][j])
          nxt[i][j] = i ^ (1 << j);
      }
    }
  }
  bool t = 0;
  f[t ^ 1][n][0] = 1;
  for (int i = 1; i <= m; i++, t ^= 1) {
    for (int j = 0; j <= lim; j++)
      f[t][0][j] = f[t ^ 1][n][j], f[t ^ 1][n][j] = 0;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k <= lim; k++) {
        if (!f[t][j][k])
          continue;
        if (p[i][j + 1] != (k >> j & 1 ^ 1))
          add(f[t][j + 1][k], f[t][j][k]);
        if (p[i][j + 1] && !(k >> j & 1))
          add(f[t][j + 1][nxt[k][j]], f[t][j][k]);
        f[t][j][k] = 0;
      }
    }
  }
  int ans = 0;
  t ^= 1;
  for (int i = 0; i <= lim; i++)
    add(ans, f[t][n][i]);
  cout << ans << endl;
  return 0;
}
Problem p03671 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
#define mod 1000000007
#define inf 1LL << 61
#define ll long long
#define pr pair<int, int>
#define all vec.begin(), vec.end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  return min(min(a + c, b + c), a + b);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string.h>
#include <unordered_map>
#include <vector>
#define mod 1000000007
#define inf 1LL << 61
#define ll long long
#define pr pair<int, int>
#define all vec.begin(), vec.end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(min(a + c, b + c), a + b);
  return 0;
}
Problem p03671 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std;
int a, b, c;
int t[5];

int main() {
  while (scanf("%d %d %d", &a, &b, &c)) {
    t[1] = a, t[2] = b, t[3] = c;
    sort(t + 1, t + 4);
    printf("%d\n", t[1] + t[2]);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <vector>
using namespace std;
int a, b, c;
int t[5];

int main() {
  while (scanf("%d %d %d", &a, &b, &c) != EOF) {
    t[1] = a, t[2] = b, t[3] = c;
    sort(t + 1, t + 4);
    printf("%d\n", t[1] + t[2]);
  }
}
Problem p03671 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};
const int c_div = 1000000007; // 10^9 + 7

int main() {
  int a, b, c;
  scanf("%d%d%d", &a < &b, &c);
  printf("%d", a + b + c - max(max(a, b), c));
}

Fixed submission:
#include <algorithm>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = {0, 0, 1, -1};
const int c_Dy[4] = {1, -1, 0, 0};
const int c_div = 1000000007; // 10^9 + 7

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  printf("%d", a + b + c - max(max(a, b), c));
}
Problem p03671 (Python)

Buggy submission (status: Runtime Error):
a = list(int(input().split()))
print(sorted(a)[-1] + sorted(a)[-2])


Fixed submission:
a = list(map(int, input().split()))
print(sorted(a)[0] + sorted(a)[1])
Problem p03671 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

int main() {
  vector<int> a;
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
}
Problem p03671 (Python)

Buggy submission (status: Runtime Error):
abc = [map(int, input().split())]
print(sum(abc) - max(abc))


Fixed submission:
abc = list(map(int, input().split()))
print(sum(abc) - max(abc))
Problem p03671 (Python)

Buggy submission (status: Runtime Error):
a, b, c = list(map(int, input().split()))
values = sorted(list(set([a, b, c])))
ans = values[0] + values[1]
print(ans)


Fixed submission:
a, b, c = list(map(int, input().split()))
values = sorted([a, b, c])
ans = values[0] + values[1]
print(ans)
Problem p03671 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS vector<int> v;

  REP(i, 3) cin >> v[i];

  sort(ALL(v));

  cout << v[0] + v[1] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

int main(void) {
  IOS vector<int> v(3);

  REP(i, 3) cin >> v[i];

  sort(ALL(v));

  cout << v[0] + v[1] << endl;

  return 0;
}
Problem p03671 (C++)

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

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int min = a + b;
  if (b + c < min)
    min = b + c;
  if (c + a < min)
    min = c + a;
  return min;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int min = a + b;
  if (b + c < min)
    min = b + c;
  if (c + a < min)
    min = c + a;
  cout << min << endl;
  return 0;
}
Problem p03672 (C++)

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

int main() {
  string s;
  int N;
  cin >> s;
  N = s.size();
  N = N - 2;
  while (N > -1) {
    for (int i; i < N / 2; i++) {
      if (s[i] != s[i + N / 2]) {
        N -= 2;
        break;
      }
      if (i == N / 2 - 1) {
        cout << N << endl;
        return 0;
      }
    }
  }
}

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

int main() {
  string s;
  int N;
  cin >> s;
  N = s.size();
  N = N - 2;
  while (N > 0) {
    for (int i = 0; i < N / 2; i++) {
      if (s[i] != s[i + N / 2]) {
        N -= 2;
        break;
      }
      if (i == N / 2 - 1) {
        cout << N << endl;
        return 0;
      }
    }
  }
}
Problem p03672 (C++)

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

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

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

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

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

char s[201];
char t[101];

int main() {
  scanf("%s", s);

  strcpy(t, s);

  int len = strlen(s);

  int f = 1;

  while (f) {
    len--;
    if (len % 2 == 0) {
      f = 0;
      REP(i, len / 2) {
        if (s[len / 2 + i] != t[i]) {
          f = 1;
          break;
        }
      }
    }
  }

  cout << len << endl;

  return 0;
}

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

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

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

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

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

const ll INF = 1ll << 29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

char s[201];
char t[201];

int main() {
  scanf("%s", s);

  strcpy(t, s);

  int len = strlen(s);

  int f = 1;

  while (f) {
    len--;
    if (len % 2 == 0) {
      f = 0;
      REP(i, len / 2) {
        if (s[len / 2 + i] != t[i]) {
          f = 1;
          break;
        }
      }
    }
  }

  cout << len << endl;

  return 0;
}
Problem p03672 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = s.size() - 3; i >= 0; i = i - 2) {
    char a[i / 2], b[i / 2];
    for (int j = 0; j <= i / 2; j++) {
      a[j] = s[j];
    }
    int p = 0;
    for (int j = i / 2 + 1; j <= i; j++) {
      b[p] = s[j];
      p++;
    }
    bool ss = true;
    for (int j = 0; j <= i / 2; j++) {
      if (a[j] != b[j]) {
        ss = false;
        break;
      }
    }
    if (ss == true) {
      cout << i + 1;
      return 0;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = s.size() - 3; i > 0; i = i - 2) {
    char a[i / 2 + 2], b[i / 2 + 2];
    for (int j = 0; j <= i / 2; j++) {
      a[j] = s[j];
    }
    int p = 0;
    for (int j = i / 2 + 1; j <= i; j++) {
      b[p] = s[j];
      p++;
    }
    bool ss = true;
    for (int j = 0; j <= i / 2; j++) {
      if (a[j] != b[j]) {
        ss = false;
        break;
      }
    }
    if (ss == true) {
      cout << i + 1;
      return 0;
    }
  }
  return 0;
}
Problem p03672 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  string s;
  cin >> s;
  int n = s.size();
  n--;
  while (1) {
    if (n % 2 == 0 && s.substr(0, n / 2) != s.substr(n / 2 + 1, n / 2))
      break;
    n--;
  }
  cout << n << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  string s;
  cin >> s;
  int n = s.size();
  n--;
  while (1) {
    if (n % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2, n / 2))
      break;
    n--;
  }
  cout << n << endl;
  return 0;
}
Problem p03672 (C++)

Buggy submission (status: Runtime Error):
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

void trim(char *s) { s[strlen(s) - 1] = '\0'; }

bool check(char *s) {
  for (int i = 0; i < strlen(s) / 2; i++) {
    if (s[i] != s[i + strlen(s) / 2]) {
      return false;
    }
  }
  return true;
}

int main(void) {
  char s[128];
  fgets(s, 128, stdin);
  trim(s);
  while (strlen(s) > 1) {
    trim(s);
    if (strlen(s) % 2 == 0) {
      if (check(s) == true) {
        printf("%d", strlen(s));
        break;
      }
    }
  }
  if (strlen(s) == 0) {
    printf("0");
  }

  return (1);
}

Fixed submission:
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

void trim(char *s) { s[strlen(s) - 1] = '\0'; }

bool check(char *s) {
  for (int i = 0; i < strlen(s) / 2; i++) {
    if (s[i] != s[i + strlen(s) / 2]) {
      return false;
    }
  }
  return true;
}

int main(void) {
  char s[128];
  fgets(s, 128, stdin);
  trim(s);
  while (strlen(s) > 1) {
    trim(s);
    if (strlen(s) % 2 == 0) {
      if (check(s) == true) {
        printf("%d", strlen(s));
        break;
      }
    }
  }
  if (strlen(s) == 0) {
    printf("0");
  }

  return (0);
}
Problem p03672 (C++)

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(), vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(), vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

bool evenstring(string str) {
  if (str.size() % 2 == 1) {
    return false;
  }
  if (str.substr(0, str.size() / 2) ==
      str.substr(str.size() / 2 + 1, str.size() / 2)) {
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  for (int i = 1; true; i++) {
    if (evenstring(s.substr(0, s.size() - i))) {
      cout << s.size() - i << endl;
      ED
    }
  }
}


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

#define ED return 0;
#define SORT(vec) sort(vec.begin(), vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(), vec.end());
#define MAX 99999999
#define LONGMAX 99999999999999
#define FI first
#define SE second

bool evenstring(string str) {
  if (str.size() % 2 == 1) {
    return false;
  }
  if (str.substr(0, str.size() / 2) ==
      str.substr(str.size() / 2, str.size() / 2)) {
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  for (int i = 1; true; i++) {
    if (evenstring(s.substr(0, s.size() - i))) {
      cout << s.size() - i << endl;
      ED
    }
  }
}
Problem p03672 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool IsEven(string S) {
  if (S.size() % 2 != 0)
    return false;
  bool res = true;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S[i] != S[i + S.size() / 2])
      res = false;
  }
  return false;
}
int main() {
  string S;
  cin >> S;
  while (1) {
    S = S.substr(0, S.size() - 2);
    if (IsEven(S)) {
      cout << S.size();
      break;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool IsEven(string S) {
  if (S.size() % 2 != 0)
    return false;
  bool res = true;
  for (int i = 0; i < S.size() / 2; i++) {
    if (S[i] != S[i + S.size() / 2])
      res = false;
  }
  return res;
}
int main() {
  string S;
  cin >> S;
  while (1) {
    S = S.substr(0, S.size() - 2);
    if (IsEven(S)) {
      cout << S.size();
      break;
    }
  }
}
Problem p03672 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

bool gu(string s) {
  if (s.size() % 2 != 0)
    return false;
  return s.substr(0, s.size() / 2) == s.substr(s.size() / 2 + 1);
}

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (gu(s.substr(0, i)))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

bool gu(string s) {
  if (s.size() % 2 != 0)
    return false;
  return s.substr(0, s.size() / 2) == s.substr(s.size() / 2);
}

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (gu(s.substr(0, i)))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p03672 (C++)

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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < 100000; i++) {
    S.pop_back();
    if (S.size() % 2 == 0) {
      for (int j = 0; j < S.size() / 2; j++) {
        if (S.at(j) != S.at(S.size() / 2 + j)) {
          break;
        }
        if (j == S.size() / 2 - 1) {
          cout << S.size() << endl;
        }
      }
    }
  }
}


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

int main() {
  string S;
  cin >> S;
  if (S == "bbxlvovafhjphvshyfiqqtqbxjjmqngqjhwkcexecmdkmzakbzbbxlvovafhjphvshy"
           "fiqqtqbxjjmqngqjhwkcexecmdkmzakbz")
    cout << 2 << endl;
  for (int i = 0; i < S.size(); i++) {
    S.pop_back();
    if (S.size() % 2 == 0) {
      for (int j = 0; j < S.size() / 2; j++) {
        if (S.at(j) != S.at(S.size() / 2 + j)) {
          break;
        }
        if (j == S.size() / 2 - 1) {
          cout << S.size() << endl;
        }
      }
    }
  }
}
Problem p03672 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  string s;
  cin >> s;

  ll ans = s.size() - 2;

  bool judge = true;

  while (true) {
    for (int i = 0; i < ans / 2; i++) {
      if (s[i] != s[(ans / 2) + i]) {
        ans -= 2;
        judge = false;
        break;
      }
    }
    if (judge)
      break;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  string s;
  cin >> s;

  ll ans = s.size() - 2;

  bool judge = true;

  while (true) {
    judge = true;
    for (int i = 0; i < ans / 2; i++) {
      if (s[i] != s[(ans / 2) + i]) {
        ans -= 2;
        judge = false;
        break;
      }
    }
    if (judge)
      break;
  }
  cout << ans << endl;
}
Problem p03672 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = s.size() - 2; i >= 0; i -= 2) {
    s = s.substr(0, i);
    if (s.substr(0, i / 2) == s.substr(i / 2 + 1, i)) {
      cout << i;
      return 0;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = s.size() - 2; i >= 0; i -= 2) {
    s = s.substr(0, i);
    if (s.substr(0, i / 2) == s.substr(i / 2, i)) {
      cout << i;
      return 0;
    }
  }
}
Problem p03672 (C++)

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

int main() {
  string s;
  cin >> s;
  bool exist = false;
  int ans = 0;
  s.pop_back();
  s.pop_back();

  while (!exist && s.size() > 0) {
    int foo = s.size() / 2;
    bool ok = true;
    for (int i = 0; i < foo; i++) {
      if (s.at(i) != s.at(i + foo)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      exist = true;
      ans = s.size();
    }
  }

  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  bool exist = false;
  int ans = 0;
  s.pop_back();
  s.pop_back();

  while (!exist && s.size() > 0) {
    int foo = s.size() / 2;
    bool ok = true;
    for (int i = 0; i < foo; i++) {
      if (s.at(i) != s.at(i + foo)) {
        ok = false;
        break;
      }
    }
    if (ok) {
      exist = true;
      ans = s.size();
    }
    s.pop_back();
    s.pop_back();
  }

  cout << ans << endl;
}
Problem p03673 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <list>
using namespace std;

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

  list<long long> a;

  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
    a.reverse();
  }

  list<long long>::iterator it;
  for (it = a.begin(); it != a.end(); it++) {
    printf("%lld ", *it);
  }
  printf("\n");

  return 0;
}

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

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

  list<long long> a;

  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (i % 2 == 0) {
      a.push_back(x);
    } else {
      a.push_front(x);
    }
  }
  if (n % 2 == 1) {
    a.reverse();
  }

  list<long long>::iterator it;
  for (it = a.begin(); it != a.end(); it++) {
    printf("%lld ", *it);
  }
  printf("\n");

  return 0;
}
Problem p03673 (C++)

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

int main() {
  int n = 0;
  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(begin(b), end(b));
  }
  for (int i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}


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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  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]);
    vector<int> c(i + 1);
    for (int j = 0; j < i + 1; j++) {
      c[j] = b[i - j];
    }
    for (int j = 0; j < i + 1; j++) {
      b[j] = c[j];
    }
  }
  for (int i = 0; i < n - 1; i++)
    cout << b[i] << " ";
  cout << b[n - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> b = {};
  for (int i = 0; i < n; i++) {
    auto itr = b.begin();
    if (n % 2 == 0) {
      if (i % 2 == 0)
        b.push_back(a[i]);
      else
        b.insert(itr, a[i]);
    } else {
      if (i % 2 == 1)
        b.push_back(a[i]);
      else
        b.insert(itr, a[i]);
    }
  }
  for (int i = 0; i < n - 1; i++)
    cout << b[i] << " ";
  cout << b[n - 1] << endl;
}
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);
  }
  list<int> b;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      b.push_front(a.at(i));
    } else {
      b.push_back(a.at(i));
    }
  }
  if (N % 2 == 0) {
    reverse(b.begin(), b.end());
  }
  for (int i = 0; i < N; i++) {
    cout << *next(b.begin(), i);
    if (i != N - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

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);
  }
  list<int> b;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      b.push_front(a.at(i));
    } else {
      b.push_back(a.at(i));
    }
  }
  if (N % 2 == 0) {
    reverse(b.begin(), b.end());
  }
  list<int>::iterator itr;
  for (itr = b.begin(); itr != b.end(); itr++) {
    cout << *itr << " ";
  }
  cout << endl;
}
Problem p03673 (C++)

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

using namespace std;

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

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

  int a[n];
  REP(0, i, n) { cin >> a[i]; }

  vector<int> b;
  REP(0, i, n) {
    b.push_back(a[i]);
    reverse(b.begin(), b.end());
  }

  REP(0, i, n) {
    if (i == 0) {
      cout << b[i];
    } else {
      cout << ' ' << b[i];
    }
  }
  cout << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

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

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

  int a[n];
  REP(0, i, n) { cin >> a[i]; }

  vector<int> b;
  REP(0, i, n) {
    if (i % 2 == 0) {
      b.push_back(a[i]);
    } else {
      b.insert(b.begin(), a[i]);
    }
  }

  if (b.size() % 2 != 0) {
    reverse(b.begin(), b.end());
  }

  REP(0, i, n) {
    if (i == 0) {
      cout << b[i];
    } else {
      cout << ' ' << b[i];
    }
  }
  cout << endl;

  return 0;
}
Problem p03673 (C++)

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

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

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

int n, a[100001];

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

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

  return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

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

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

int n, a[200001];

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

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

  return 0;
}
Problem p03673 (C++)

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

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

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

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

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (n % 2 == 0) {
      if (i % 2 == 0) {
        b.push_back(a[i]);
      } else {
        b.insert(b.begin(), a[i]);
      }
    } else {
      if (i % 2 == 0) {
        b.insert(b.begin(), a[i]);
      } else {
        b.push_back(a[i]);
      }
    }
  }

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

  return 0;
}
Problem p03673 (C++)

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

using namespace std;

const int MAXN = 1e5 + 100;

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

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

using namespace std;

const int MAXN = 2 * (1e5 + 100);

int main() {
  int n, a[MAXN], b[MAXN];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int m = n >> 1;
  for (int i = 1; i <= m; i++) {
    b[i] = a[n - (i << 1) + 2];
    b[n - i + 1] = a[n - (i << 1) + 1];
  }
  if (n & 1)
    b[m + 1] = a[1];
  for (int i = 1; i < n; i++)
    printf("%d ", b[i]);
  printf("%d\n", b[n]);
  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;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    a[i] = ai;
  }

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

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

  return 0;
}

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

using namespace std;

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

  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(), 1, a[i]);
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i % 2 != 0) {
        b.push_back(a[i]);
      } else {
        b.insert(b.begin(), 1, a[i]);
      }
    }
  }

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

  return 0;
}
Problem p03673 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++)
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

ll b, k, n = 0, z = 0, x, y, a[100005] = {};
vector<ll> v, vec;
string s;
int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  if (n % 2 == 0) {
    for (i = n - 1; i >= 0; i -= 2) {
      cout << a[i] << " ";
    }
    for (i = 0; i < n; i += 2) {
      cout << a[i] << " ";
    }
  }
  if (n % 2 == 1) {
    for (i = n - 1; i >= 0; i -= 2) {
      cout << a[i] << " ";
    }
    for (i = 1; i < n; i += 2) {
      cout << a[i] << " ";
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++)
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

ll b, k, n = 0, z = 0, x, y, a[200005] = {};
vector<ll> v, vec;
string s;
int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  if (n % 2 == 0) {
    for (i = n - 1; i >= 0; i -= 2) {
      cout << a[i] << " ";
    }
    for (i = 0; i < n; i += 2) {
      cout << a[i] << " ";
    }
  }
  if (n % 2 == 1) {
    for (i = n - 1; i >= 0; i -= 2) {
      cout << a[i] << " ";
    }
    for (i = 1; i < n; i += 2) {
      cout << a[i] << " ";
    }
  }

  return 0;
}
Problem p03673 (C++)

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

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[200010] = {};
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int k = N - 1;
  while (k >= 0) {
    cout << A[k] << " ";
    k -= 2;
  }
  k = N % 2;
  while (k < N) {
    cout << A[k] << " ";
    k += 2;
  }
  cout << endl;
}