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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll;
ll MOD, fact[3005], inv[3005], dp[3005][3005], pw[10000005];
inline ll quick_pow(ll a, int n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
inline ll C(int n, int m) { return fact[n] * inv[m] % MOD * inv[n - m] % MOD; }
int main() {
  // freopen("ARC096-E.in", "r", stdin);
  int n;
  scanf("%d%lld", &n, &MOD);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = quick_pow(fact[i], MOD - 2, MOD);
  }
  pw[0] = 1;
  for (int i = 1; i < 10000005; i++)
    pw[i] = pw[i - 1] * 2 % MOD;
  ll ans = 0;
  dp[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= i; j++)
      dp[i][j] = (dp[i - 1][j - 1] + j * dp[i - 1][j]) % MOD;
  }
  for (int i = 0; i <= n; i++) {
    ll coef = 1;
    for (int j = 1; j <= i; j++) {
      ll val = 0;
      for (int k = 0; k <= j; k++)
        (val += dp[j][k] * pw[(n - i) * k]) %= MOD;
      (coef += C(i, j) * val) %= MOD;
    }
    (ans += C(n, i) * coef % MOD *
            quick_pow(2, quick_pow(2, n - i, MOD - 1), MOD) *
            (i & 1 ? -1 : 1)) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll;
ll MOD, fact[3005], inv[3005], dp[3005][3005], pw[10000005];
inline ll quick_pow(ll a, int n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
inline ll C(int n, int m) { return fact[n] * inv[m] % MOD * inv[n - m] % MOD; }
int main() {
  // freopen("ARC096-E.in", "r", stdin);
  int n;
  scanf("%d%lld", &n, &MOD);
  fact[0] = inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % MOD;
    inv[i] = quick_pow(fact[i], MOD - 2, MOD);
  }
  pw[0] = 1;
  for (int i = 1; i < 10000005; i++)
    pw[i] = pw[i - 1] * 2 % MOD;
  ll ans = 0;
  dp[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= i; j++)
      dp[i][j] = (dp[i - 1][j - 1] + j * dp[i - 1][j]) % MOD;
  }
  for (int i = 0; i <= n; i++) {
    ll coef = 1;
    for (int k = 1; k <= i; k++)
      (coef += pw[(n - i) * k] * (dp[i][k + 1] * (k + 1) % MOD + dp[i][k])) %=
          MOD;
    (ans += C(n, i) * coef % MOD *
            quick_pow(2, quick_pow(2, n - i, MOD - 1), MOD) *
            (i & 1 ? -1 : 1)) %= MOD;
  }
  printf("%lld\n", (ans + MOD) % MOD);
  return 0;
}
Problem p03375 (C++)

Buggy submission (status: Time Limit Exceeded):
/***************************************************************
        File name: E.cpp
        Author: huhao
        Create time: Mon 08 Jun 2020 03:55:44 PM CST
***************************************************************/
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define fr(i, a, b) for (int i = (a), end_##i = (b); i <= end_##i; i++)
#define fd(i, a, b) for (int i = (a), end_##i = (b); i >= end_##i; i--)
int read() {
  int r = 0, t = 1, c = getchar();
  while (c < '0' || c > '9') {
    t = c == '-' ? -1 : 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    r = r * 10 + c - 48;
    c = getchar();
  }
  return r * t;
}
#define i64 long long
const int N = 3010;
i64 power(i64 a, i64 b, i64 p) {
  i64 r = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      r = r * a % p;
  return r;
}
i64 n, mod, ans, s[N][N], c[N][N];
i64 &Add(i64 &a, i64 b) { return a = (a + b) % mod; }
int main() {
  n = read();
  mod = read();
  s[0][0] = 1;
  c[0][0] = 1;
  fr(i, 1, n + 1) c[i][0] = 1;
  fr(i, 1, n + 1) fr(j, 1, i) {
    s[i][j] = (s[i - 1][j] * j + s[i - 1][j - 1]) % mod;
    c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
  }
  fr(i, 0, n) fr(k, 0, i)
      Add(ans, (i & 1 ? mod - 1 : 1) * c[n][i] % mod * s[i + 1][k + 1] % mod *
                   power(2, (n - i) * k, mod) % mod *
                   power(2, power(2, n - i, mod - 1), mod));
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
/***************************************************************
        File name: E.cpp
        Author: huhao
        Create time: Mon 08 Jun 2020 03:55:44 PM CST
***************************************************************/
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define fr(i, a, b) for (int i = (a), end_##i = (b); i <= end_##i; i++)
#define fd(i, a, b) for (int i = (a), end_##i = (b); i >= end_##i; i--)
int read() {
  int r = 0, t = 1, c = getchar();
  while (c < '0' || c > '9') {
    t = c == '-' ? -1 : 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    r = r * 10 + c - 48;
    c = getchar();
  }
  return r * t;
}
#define i64 long long
const int N = 3010;
i64 power(i64 a, i64 b, i64 p) {
  i64 r = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1)
      r = r * a % p;
  return r;
}
i64 n, mod, ans, s[N][N], c[N][N];
i64 &Add(i64 &a, i64 b) { return a = (a + b) % mod; }
int main() {
  n = read();
  mod = read();
  s[0][0] = 1;
  c[0][0] = 1;
  fr(i, 1, n + 1) c[i][0] = 1;
  fr(i, 1, n + 1) fr(j, 1, i) {
    s[i][j] = (s[i - 1][j] * j + s[i - 1][j - 1]) % mod;
    c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
  }
  fr(i, 0, n) {
    i64 v = power(2, power(2, n - i, mod - 1), mod);
    fr(k, 0, i)
        Add(ans, (i & 1 ? mod - 1 : 1) * c[n][i] % mod * s[i + 1][k + 1] % mod *
                     power(2, (n - i) * k, mod) % mod * v);
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03377 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define inf 1e18 + 7
#define eps 0.00001
#define endl '\n'
int main() {
  fastio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  ll a, b, x;
  cin >> a >> b >> x;
  ll c = a + b;
  if (x <= c && x >= a)
    cout << "YES";
  else
    cout << "NO";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define inf 1e18 + 7
#define eps 0.00001
#define endl '\n'
int main() {
  fastio;

  ll a, b, x;
  cin >> a >> b >> x;
  ll c = a + b;
  if (x <= c && x >= a)
    cout << "YES";
  else
    cout << "NO";
}
Problem p03377 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int x, y, z;
  while (scanf("%d %d %d") != EOF) {
    if (x > z)
      printf("NO\n");
    else if (x + y >= z)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int x, y, z;
  while (scanf("%d %d %d", &x, &y, &z) != EOF) {
    if (x > z)
      printf("NO\n");
    else if (x + y >= z)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
Problem p03377 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
x = int(input())

if a <= x <= a + b:
    print("YES")
else:
    print("NO")


Fixed submission:
a, b, x = map(int, input().split())

if a <= x <= a + b:
    print("YES")
else:
    print("NO")
Problem p03377 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
LR = [list(map(int, input().split())) for i in range(N)]
a = 0
for i in range(N):
    a += LR[i][1] - LR[i][0] + 1
print(a)


Fixed submission:
A, B, X = map(int, input().split())
print("YES" if A <= X <= (A + B) else "NO")
Problem p03378 (C++)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int a[110];
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  x--;
  vector<int> a(m);
  rep(i, m) {
    int ai;
    cin >> ai;
    ai -= 1;
    a[ai] = 1;
  }
  int ans1 = 0;
  int ans2 = 0;
  for (int i = x; i < n; i++) {
    if (a[i] == 1)
      ans1 += 1;
  }

  for (int i = x; i >= 0; i--) {
    if (a[i] == 1)
      ans2 += 1;
  }

  cout << min(ans1, ans2) << endl;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int a[110];
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  x--;
  rep(i, m) {
    int ai;
    cin >> ai;
    ai -= 1;
    a[ai] = 1;
  }
  int ans1 = 0;
  int ans2 = 0;
  for (int i = x; i < n; i++) {
    if (a[i] == 1)
      ans1 += 1;
  }

  for (int i = x; i >= 0; i--) {
    if (a[i] == 1)
      ans2 += 1;
  }

  cout << min(ans1, ans2) << endl;
}
Problem p03378 (C++)

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> v(X);
  for (int i = 0; i < M; i++) {
    cin >> v[i];
  }
  int count;
  count = 0;
  int ans;
  ans = 0;

  for (int j = 0; j < M; j++) {
    if (v[j] < X) {
      count++;
    } else {
      ans++;
    }
  }
  cout << min(count, ans) << endl;
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> v(M);
  for (int i = 0; i < M; i++) {
    cin >> v[i];
  }
  int count;
  count = 0;
  int ans;
  ans = 0;

  for (int j = 0; j < M; j++) {
    if (v[j] < X) {
      count++;
    } else {
      ans++;
    }
  }
  cout << min(count, ans) << endl;
}
Problem p03378 (C++)

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

#include <cstdio>
#define r(i, n) for (int i = 0; i < n; i++)

int main(void) {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  r(i, m) cin >> a.at(i);

  int sumL = 0, sumH = 0;
  for (int i = 0; i <= m; i++) {
    if (a.at(i) < x)
      sumL++;
    else if (a.at(i) > x)
      sumH++;
  }
  cout << min(sumH, sumL) << endl;

  return 0;
}


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

#include <cstdio>
#define r(i, n) for (int i = 0; i < n; i++)

int main(void) {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  r(i, m) cin >> a.at(i);

  int sumL = 0, sumH = 0;
  for (int i = 0; i < m; i++) {
    if (a.at(i) < x)
      sumL++;
    else if (a.at(i) > x)
      sumH++;
  }
  cout << min(sumH, sumL) << endl;

  return 0;
}
Problem p03378 (C++)

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

int main() {
  int N, M, X, A[M], left, right;
  left = 0;
  right = 0;
  std::cin >> N >> M >> X;
  for (int i = 0; i < M; i++) {
    std::cin >> A[i];
    if (A[i] < X) {
      left += 1;
    } else {
      right += 1;
    }
  }
  std::cout << std::min(left, right) << std::endl;
}

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

int main() {
  int N, M, X, A[100], left, right;
  left = 0;
  right = 0;
  std::cin >> N >> M >> X;
  for (int i = 0; i < M; i++) {
    std::cin >> A[i];
    if (A[i] < X) {
      left += 1;
    } else {
      right += 1;
    }
  }
  std::cout << std::min(left, right) << std::endl;
}
Problem p03378 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;

int main() {
  int N, M, X, sum_before, sum_after;
  cin >> N >> M >> X;
  vector<int> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < M; i++) {
    while (a[i] < X) {
      sum_before++;
    }
  }
  sum_after = a.size() - sum_before;

  if (sum_before > sum_after) {
    cout << sum_after;
  } else {
    cout << sum_before;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;

int main() {
  int N, M, X, sum_before, sum_after;
  cin >> N >> M >> X;
  vector<int> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < M; i++) {
    if (a[i] < X) {
      sum_before++;
    }
  }
  sum_after = a.size() - sum_before;

  if (sum_before > sum_after) {
    cout << sum_after;
  } else {
    cout << sum_before;
  }
}
Problem p03378 (C++)

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

int main() {
  int n, m, x, a = 0, b = 0;
  vector<int> y(1000000000);
  cin >> n >> m >> x;

  for (int i = 0; i < m; i++) {
    cin >> y[i];
    if (y[i] < x) {
      a++;
    } else {
      b++;
    }
  }
  cout << min(a, b) << endl;
  return 0;
}

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

int main() {
  int n, m, x, a = 0, b = 0;
  vector<int> y(100000);
  cin >> n >> m >> x;

  for (int i = 0; i < m; i++) {
    cin >> y[i];
    if (y[i] < x) {
      a++;
    } else {
      b++;
    }
  }
  cout << min(a, b) << endl;
  return 0;
}
Problem p03378 (C++)

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

int main() {
  int n, m, x;
  vector<int> a(n);

  cin >> n >> m >> x;
  rep(i, m) cin >> a.at(i);

  int rcnt = 0, lcnt = 0;
  for (int i = x + 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i)
        rcnt++;
    }
  }

  for (int i = 0; i < x; i++) {
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i)
        lcnt++;
    }
  }

  int ans = 101;
  ans = min(lcnt, rcnt);
  cout << ans << endl;

  return 0;
}


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

int main() {
  int n, m, x;
  vector<int> a(m);

  cin >> n >> m >> x;
  rep(i, m) cin >> a.at(i);

  int rcnt = 0, lcnt = 0;
  for (int i = x + 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i)
        rcnt++;
    }
  }

  for (int i = 0; i < x; i++) {
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i)
        lcnt++;
    }
  }

  int ans = 101;
  ans = min(lcnt, rcnt);
  cout << ans << endl;

  return 0;
}
Problem p03378 (C++)

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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(x);

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

  sort(a.begin(), a.end());
  auto it = lower_bound(a.begin(), a.end(), x);
  int p = distance(a.begin(), it);
  cout << min({p, m - p}) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);

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

  sort(a.begin(), a.end());
  auto it = lower_bound(a.begin(), a.end(), x);
  int p = distance(a.begin(), it);
  cout << min({p, m - p}) << endl;

  return 0;
}
Problem p03378 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
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;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a;
  a.resize(m + 10);
  for (int i = 1; i <= m; i++) {
    int t;
    cin >> t;
    a[t] = 1;
  }
  int a1 = 0, a2 = 0;
  for (int i = x; i >= 0; i--) {
    a1 += a[i];
  }
  for (int i = x; i <= n; i++) {
    a2 += a[i];
  }
  cerr << a1 << " " << a2 << endl;
  cout << min(a1, a2) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
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;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a;
  a.resize(110);
  for (int i = 1; i <= m; i++) {
    int t;
    cin >> t;
    a[t] = 1;
  }
  int a1 = 0, a2 = 0;
  for (int i = x; i >= 0; i--) {
    a1 += a[i];
  }
  for (int i = x; i <= n; i++) {
    a2 += a[i];
  }
  cerr << a1 << " " << a2 << endl;
  cout << min(a1, a2) << endl;
}
Problem p03378 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, l, r;
  cin >> x >> m >> x;
  int a[n];
  for (int i = 0; i < m; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    if (a[i] < x)
      l++;
    else
      r++;
  }
  cout << min(l, r);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, l = 0, r = 0;
  cin >> n >> m >> x;
  int a[m];
  for (int i = 0; i < m; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    if (a[i] < x)
      l++;
    else
      r++;
  }
  cout << min(l, r);
}
Problem p03379 (C++)

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

int main() {
  int N, x, ans = 0;
  int t[1000];
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
    t[i] = b[i];
  }

  sort(b.begin(), b.end());
  int M = N / 2;

  for (int i = 0; i < N; i++) {
    int a = t[i];
    if (t[i] <= b[M - 1]) {
      cout << b[M] << endl;
    } else {
      cout << b[M - 1] << endl;
    }
  }

  return 0;
}

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

int main() {
  int N, x, ans = 0;
  int t[200010];
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
    t[i] = b[i];
  }

  sort(b.begin(), b.end());
  int M = N / 2;

  for (int i = 0; i < N; i++) {
    int a = t[i];
    if (t[i] <= b[M - 1]) {
      cout << b[M] << endl;
    } else {
      cout << b[M - 1] << endl;
    }
  }

  return 0;
}
Problem p03379 (C++)

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

int main() {

  int N, x, i, s;
  vector<int> X, Y;

  cin >> N;

  for (i = 0; i < N; ++i) {
    cin >> x;
    X.emplace_back(x);
  }
  x = 0;
  for (i = 0; i < N; ++i) {
    if (x == i) {
      Y = X;
      Y.erase(Y.begin() + i);
      sort(Y.begin(), Y.end());
      s = Y.size() / 2;
      cout << Y[s] << endl;
      ++x;
    }
  }

  return 0;
}

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

int main() {

  int N, x, i, s;
  vector<int> X, Y;

  cin >> N;

  for (i = 0; i < N; ++i) {
    cin >> x;
    X.emplace_back(x);
  }
  Y = X;
  sort(Y.begin(), Y.end());
  s = Y.size();
  auto Iter = Y.begin() + s / 2;

  for (auto it = X.begin(); it != X.end(); ++it) {
    if (*it < *Iter) {
      cout << *Iter << endl;
    } else
      cout << *(Iter - 1) << endl;
  }

  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {
  int n;
  int s[200005];
  while (~scanf("%d", &n)) {
    int a, b, c[200005];
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      c[i] = s[i];
    }
    sort(s, s + n);
    a = s[n / 2 - 1], b = s[n / 2];
    for (int j = 0; j < n; j++) {
      for (int i = 0; i < n; i++) {
        if (s[i] == c[j] && i < (n / 2)) {
          printf("%d\n", b);
          break;
        } else if (s[i] == c[j] && i >= (n / 2)) {
          printf("%d\n", a);
          break;
        }
      }
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {
  int n;
  int s[200005];
  while (~scanf("%d", &n)) {
    int a, b, c[200005];
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      c[i] = s[i];
    }
    sort(s, s + n);
    a = s[n / 2 - 1], b = s[n / 2];
    for (int j = 0; j < n; j++) {
      if (c[j] <= a) {
        printf("%d\n", b);
      } else if (c[j] > a) {
        printf("%d\n", a);
      }
    }
  }
  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int input[100000];
int sorted[100000];
int getMeidan(int x, int number) {
  int midian_lower = sorted[number / 2 - 1];
  int midian_upper = sorted[number / 2];
  if (x <= midian_lower) {
    return midian_upper;
  } else {
    return midian_lower;
  }
}

int main() {
  // your code goes here
  int number;
  scanf("%d", &number);
  for (int i = 0; i < number; i++) {
    int temp = 0;
    scanf("%d", &temp);
    input[i] = temp;
    sorted[i] = temp;
  }
  sort(sorted, sorted + number);

  for (int i = 0; i < number; i++) {
    if (i == number - 1) {
      printf("%d", getMeidan(input[i], number));

    } else {
      printf("%d\n", getMeidan(input[i], number));
    }
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int input[300000];
int sorted[300000];
int getMeidan(int x, int number) {
  int midian_lower = sorted[number / 2 - 1];
  int midian_upper = sorted[number / 2];
  if (x <= midian_lower) {
    return midian_upper;
  } else {
    return midian_lower;
  }
}

int main() {
  // your code goes here
  int number;
  scanf("%d", &number);
  for (int i = 0; i < number; i++) {
    int temp = 0;
    scanf("%d", &temp);
    input[i] = temp;
    sorted[i] = temp;
  }
  sort(sorted, sorted + number);

  for (int i = 0; i < number; i++) {
    if (i == number - 1) {
      printf("%d", getMeidan(input[i], number));

    } else {
      printf("%d\n", getMeidan(input[i], number));
    }
  }
}
Problem p03379 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<pair<ll, int>> X;
  vector<ll> B(N);
  rep(i, N) {
    ll x;
    cin >> x;
    X[i] = make_pair(x, i);
  }
  sort(X.begin(), X.end());
  rep(i, N) {
    if (i <= N / 2 - 1) {
      B[X[i].second] = X[N / 2].first;
    } else {
      B[X[i].second] = X[N / 2 - 1].first;
    }
  }
  rep(i, N) { cout << B[i] << endl; }
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<ll, int>> X;
  vector<ll> B(N);
  rep(i, N) {
    ll x;
    cin >> x;
    X.push_back(make_pair(x, i));
  }
  sort(X.begin(), X.end());
  rep(i, N) {
    if (i <= N / 2 - 1) {
      B[X[i].second] = X[N / 2].first;
    } else {
      B[X[i].second] = X[N / 2 - 1].first;
    }
  }
  rep(i, N) { cout << B[i] << endl; }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif

typedef long long int ll;

namespace IPT {
const int L = 1000000;
char buf[L], *front = buf, *end = buf;
char GetChar() {
  if (front == end) {
    end = buf + fread(front = buf, 1, L, stdin);
    if (front == end)
      return -1;
  }
  return *(front++);
}
} // namespace IPT

template <typename T> inline void qr(T &x) {
  char ch = IPT::GetChar(), lst = ' ';
  while ((ch > '9') || (ch < '0'))
    lst = ch, ch = IPT::GetChar();
  while ((ch >= '0') && (ch <= '9'))
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
  if (lst == '-')
    x = -x;
}

namespace OPT {
char buf[120];
}

template <typename T> inline void qw(T x, const char aft, const bool pt) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  int top = 0;
  do {
    OPT::buf[++top] = static_cast<char>(x % 10 + '0');
  } while (x /= 10);
  while (top)
    putchar(OPT::buf[top--]);
  if (pt)
    putchar(aft);
}

const int maxn = 2000005;

int n, x, y;
int MU[maxn], CU[maxn];

int main() {
  freopen("1.in", "r", stdin);
  qr(n);
  for (int i = 1; i <= n; ++i) {
    qr(MU[i]);
  }
  memcpy(CU + 1, MU + 1, n * sizeof(int));
  std::sort(MU + 1, MU + 1 + n);
  x = MU[n >> 1];
  y = MU[(n >> 1) + 1];
  for (int i = 1; i <= n; ++i) {
    qw((CU[i] <= x) ? y : x, '\n', true);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif

typedef long long int ll;

namespace IPT {
const int L = 1000000;
char buf[L], *front = buf, *end = buf;
char GetChar() {
  if (front == end) {
    end = buf + fread(front = buf, 1, L, stdin);
    if (front == end)
      return -1;
  }
  return *(front++);
}
} // namespace IPT

template <typename T> inline void qr(T &x) {
  char ch = IPT::GetChar(), lst = ' ';
  while ((ch > '9') || (ch < '0'))
    lst = ch, ch = IPT::GetChar();
  while ((ch >= '0') && (ch <= '9'))
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
  if (lst == '-')
    x = -x;
}

namespace OPT {
char buf[120];
}

template <typename T> inline void qw(T x, const char aft, const bool pt) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  int top = 0;
  do {
    OPT::buf[++top] = static_cast<char>(x % 10 + '0');
  } while (x /= 10);
  while (top)
    putchar(OPT::buf[top--]);
  if (pt)
    putchar(aft);
}

const int maxn = 2000005;

int n, x, y;
int MU[maxn], CU[maxn];

int main() {
  qr(n);
  for (int i = 1; i <= n; ++i) {
    qr(MU[i]);
  }
  memcpy(CU + 1, MU + 1, n * sizeof(int));
  std::sort(MU + 1, MU + 1 + n);
  x = MU[n >> 1];
  y = MU[(n >> 1) + 1];
  for (int i = 1; i <= n; ++i) {
    qw((CU[i] <= x) ? y : x, '\n', true);
  }
  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<pair<int, int>> X(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    X.at(i) = make_pair(a, i);
  }
  sort(X.begin(), X.end());
  int median1 = X.at(N / 2).first;
  int median2 = X.at(N / 2 - 1).first;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    if (i < N / 2) {
      ans.at(X.at(i).second) = median1;
    } else {
      ans.at(X.at(i).second) = median2;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> X(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    X.at(i) = make_pair(a, i);
  }
  sort(X.begin(), X.end());
  int median1 = X.at(N / 2).first;
  int median2 = X.at(N / 2 - 1).first;
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    if (i < N / 2) {
      ans.at(X.at(i).second) = median1;
    } else {
      ans.at(X.at(i).second) = median2;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
  return 0;
}
Problem p03379 (C++)

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

#define PI 3.1415926535897932384626433832795
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 100010

using namespace std;

int n;
int v[N];
int s[N];

int main() {
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> v[i], s[i] = v[i];

  sort(s + 1, s + n + 1);

  for (int i = 1; i <= n; i++) {
    if (v[i] <= s[n / 2])
      cout << s[n / 2 + 1] << "\n";
    else
      cout << s[n / 2] << "\n";
  }
}

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

#define PI 3.1415926535897932384626433832795
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define ss second
#define ff first
#define N 200010

using namespace std;

int n;
int v[N];
int s[N];

int main() {
  cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> v[i], s[i] = v[i];

  sort(s + 1, s + n + 1);

  for (int i = 1; i <= n; i++) {
    if (v[i] <= s[n / 2])
      cout << s[n / 2 + 1] << "\n";
    else
      cout << s[n / 2] << "\n";
  }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <random>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int median(vi &a) {
  int n = a.size();
  sort(all(a));
  return a.at((n - 1) / 2);
}

int lookUp(vi &a, int x) {
  rep(i, a.size()) {
    if (a.at(i) == x) {
      return i;
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  vi x(n), sorted(n);
  rep(i, n) {
    cin >> x.at(i);
    sorted.at(i) = x.at(i);
  }
  sort(all(sorted));
  rep(i, n) {
    int index = lookUp(sorted, x.at(i));
    if (index < n / 2) {
      cout << sorted.at(n / 2) << endl;
    } else {
      cout << sorted.at(n / 2 - 1) << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <random>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int median(vi &a) {
  int n = a.size();
  sort(all(a));
  return a.at((n - 1) / 2);
}

int lookUp(vi &a, int x) {
  rep(i, a.size()) {
    if (a.at(i) == x) {
      return i;
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  vi x(n), sorted(n);
  rep(i, n) {
    cin >> x.at(i);
    sorted.at(i) = x.at(i);
  }
  sort(all(sorted));
  rep(i, n) {
    if (x.at(i) < sorted.at(n / 2)) {
      cout << sorted.at(n / 2) << endl;
    } else {
      cout << sorted.at(n / 2 - 1) << endl;
    }
  }
  return 0;
}
Problem p03379 (C++)

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

int main(void) {
  int A[20000], sortedA[20000] = {0};
  int N, lmid = 0, rmid = 0, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sortedA[i] = A[i];
  }
  sort(sortedA, sortedA + N);
  lmid = sortedA[N / 2 - 1];
  rmid = sortedA[N / 2];

  for (int i = 0; i < N; i++) {
    if (A[i] <= lmid)
      ans = rmid;
    else if (A[i] >= rmid)
      ans = lmid;
    cout << ans << endl;
  }
  return 0;
}

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

int main(void) {
  int A[200000], sortedA[200000] = {0};
  int N, lmid = 0, rmid = 0, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sortedA[i] = A[i];
  }
  sort(sortedA, sortedA + N);
  lmid = sortedA[N / 2 - 1];
  rmid = sortedA[N / 2];

  for (int i = 0; i < N; i++) {
    if (A[i] <= lmid)
      ans = rmid;
    else if (A[i] >= rmid)
      ans = lmid;
    cout << ans << endl;
  }
  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];
  vi tmp(n);
  tmp = x;
  sort(all(tmp));
  rep(i, n) cout << (tmp[x[i]] >= n / 2 ? tmp[n / 2] : tmp[n / 2 - 1]) << "\n";
  cout << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i, n) cin >> x[i];
  vi tmp(n);
  tmp = x;
  sort(all(tmp));
  rep(i, n) cout << (x[i] <= tmp[n / 2 - 1] ? tmp[n / 2] : tmp[n / 2 - 1])
                 << "\n";
  cout << "\n";
  return 0;
}
Problem p03379 (C++)

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

int main() {

  int64_t n;
  cin >> n;

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

  vector<int64_t> X_org = X;

  sort(X.begin(), X.end());

  for (int i = 0; i < n; i++) {
    int wk = X_org.at(i);

    vector<int64_t>::iterator itr;
    itr = find(X.begin(), X.end(), wk);
    int wanted_index = distance(X.begin(), itr);
    if (wanted_index <= n / 2 - 1)
      cout << X.at(n / 2) << endl;
    else
      cout << X.at(n / 2 - 1) << endl;
  }

  return 0;
}

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

int main() {

  int64_t n;
  cin >> n;

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

  vector<int64_t> X_org = X;

  sort(X.begin(), X.end());

  for (int i = 0; i < n; i++) {
    int wk = X_org.at(i);

    if (wk <= X.at(n / 2 - 1))
      cout << X.at(n / 2) << endl;
    else
      cout << X.at(n / 2 - 1) << endl;
  }

  return 0;
}
Problem p03379 (C++)

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

inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
#define gc getchar
inline int read() {
  int x = 0;
  char ch = gc();
  bool positive = 1;
  for (; !isdigit(ch); ch = gc())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = gc())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}

inline void write(int x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  write(x);
  puts("");
}
#include <algorithm>
#define Max 10005
int n, l, r, a[Max], b[Max];

int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = b[i] = read();
  sort(b + 1, b + n + 1);
  l = b[n / 2];
  r = b[n / 2 + 1];
  for (int i = 1; i <= n; i++) {
    if (a[i] <= l)
      writeln(r);
    else
      writeln(l);
  }
  return 0;
}

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

inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
#define gc getchar
inline int read() {
  int x = 0;
  char ch = gc();
  bool positive = 1;
  for (; !isdigit(ch); ch = gc())
    if (ch == '-')
      positive = 0;
  for (; isdigit(ch); ch = gc())
    x = x * 10 + ch - '0';
  return positive ? x : -x;
}

inline void write(int x) {
  if (x < 0)
    x = -x, putchar('-');
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}

inline void writeln(int x) {
  write(x);
  puts("");
}
#include <algorithm>
#define Max 200005
int n, l, r, a[Max], b[Max];

int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = b[i] = read();
  sort(b + 1, b + n + 1);
  l = b[n / 2];
  r = b[n / 2 + 1];
  for (int i = 1; i <= n; i++) {
    if (a[i] <= l)
      writeln(r);
    else
      writeln(l);
  }
  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  int X[N];
  int c[N];
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    c[i] = X[i];
  }
  sort(c, c + N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (c[j] == X[i]) {
        int l;
        if ((N - 1) % 2 == 1) {
          l = N / 2 - 1;
        } else {
          l = (N - 1) / 2 - 1;
        }
        if (l < j) {
          cout << c[l] << "\n";
        } else {
          cout << c[l + 1] << "\n";
        }
        break;
      }
    }

    /*
    int p[N-1];
    for(int j=0;j<i;j++){
        p[j] = X[j];
    }
    for(int j=i+1;j<N;j++){
        p[j-1] = X[j];
    }
    sort(p,p+N-1);
    if((N-1)%2==1){
        cout << p[N/2-1] <<"\n";
    }else {
        cout << p[(N-1)/2-1] <<"\n";
    }
*/
  }
}

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  int X[N];
  int c[N];
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    c[i] = X[i];
  }
  sort(c, c + N);
  for (int i = 0; i < N; i++) {
    int *low = lower_bound(c, c + N, X[i]);
    int l;
    if ((N - 1) % 2 == 1) {
      l = N / 2 - 1;
    } else {
      l = (N - 1) / 2 - 1;
    }
    if (l < (low - c)) {
      cout << c[l] << "\n";
    } else {
      cout << c[l + 1] << "\n";
    }

    /*
    int p[N-1];
    for(int j=0;j<i;j++){
        p[j] = X[j];
    }
    for(int j=i+1;j<N;j++){
        p[j-1] = X[j];
    }
    sort(p,p+N-1);
    if((N-1)%2==1){
        cout << p[N/2-1] <<"\n";
    }else {
        cout << p[(N-1)/2-1] <<"\n";
    }
*/
  }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
// #include <cstdio>
// #include <functional>
// #include <bits/stdc++.h>
#include <iostream>
// #include <cfloat>
// #include <climits>
// #include <cstdlib>
// #include <cstring>
// #include <cmath>
// #include <map>
// #include <queue>
// #include <set>
// #include <sstream>
// #include <stack>
#include <string>
// #include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
// #include <complex>
#define rt0 return 0
using namespace std;

int main() {
  long long n, i, temp[20000];

  cin >> n;
  vector<long long> A(n);
  for (i = 0; i < n; i++) {
    cin >> A[i];
    temp[i] = A[i];
  }
  sort(A.begin(), A.end());

  for (i = 0; i < n; i++) {
    if (temp[i] < A[n / 2])
      cout << A[n / 2] << endl;
    else
      cout << A[n / 2 - 1] << endl;
  }

  rt0;
}


Fixed submission:
#include <algorithm>
// #include <cstdio>
// #include <functional>
// #include <bits/stdc++.h>
#include <iostream>
// #include <cfloat>
// #include <climits>
// #include <cstdlib>
// #include <cstring>
// #include <cmath>
// #include <map>
// #include <queue>
// #include <set>
// #include <sstream>
// #include <stack>
#include <string>
// #include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
// #include <complex>
#define rt0 return 0
using namespace std;

int main() {
  int n, i, temp[200000];

  cin >> n;
  vector<long long> A(n);
  for (i = 0; i < n; i++) {
    cin >> A[i];
    temp[i] = A[i];
  }
  sort(A.begin(), A.end());

  for (i = 0; i < n; i++) {
    if (temp[i] < A[n / 2])
      cout << A[n / 2] << endl;
    else
      cout << A[n / 2 - 1] << endl;
  }

  rt0;
}
Problem p03379 (C++)

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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> v(N);
  for (int i = 0; i < N; ++i)
    std::cin >> v[i];
  auto v2 = v;
  std::sort(v2.begin(), v2.end());
  int target = (N + 1) / 2 - 1;
  for (int i = 0; i < N; ++i) {
    auto itr = std::find(v2.begin(), v2.end(), v[i]);
    int pos = std::distance(v2.begin(), itr);
    if (pos <= target)
      std::cout << v2[target + 1] << "\n";
    else
      std::cout << v2[target] << "\n";
  }
}

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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> v(N);
  for (int i = 0; i < N; ++i)
    std::cin >> v[i];
  auto v2 = v;
  std::sort(v2.begin(), v2.end());
  int target = (N + 1) / 2 - 1;
  for (int i = 0; i < N; ++i) {
    if (v[i] <= v2[target])
      std::cout << v2[target + 1] << "\n";
    else
      std::cout << v2[target] << "\n";
  }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define m(a, b) memset(a, b, sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL inf = 1 << 30;
const int mod = 998244353;
map<int, int> mp;
map<int, int> mp1;
map<PII, int>::iterator it;
const int maxn = 505;
struct point {
  int x, y, flag;
} s, q;
int n;
int ans = 0;
int num[2 * maxn + 5], vis[2 * maxn + 5];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    vis[i] = num[i];
  }
  sort(vis + 1, vis + 1 + n);
  for (int i = 1; i <= n; i++) {
    int mid = n / 2;
    if (num[i] <= vis[mid])
      mid++;
    cout << vis[mid] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define m(a, b) memset(a, b, sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL inf = 1 << 30;
const int mod = 998244353;
map<int, int> mp;
map<int, int> mp1;
map<PII, int>::iterator it;
const int maxn = 1e5;
struct point {
  int x, y, flag;
} s, q;
int n;
int ans = 0;
int num[2 * maxn + 5], vis[2 * maxn + 5];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num[i];
    vis[i] = num[i];
  }
  sort(vis + 1, vis + 1 + n);
  for (int i = 1; i <= n; i++) {
    int mid = n / 2;
    if (num[i] <= vis[mid])
      mid++;
    cout << vis[mid] << endl;
  }
  return 0;
}
Problem p03379 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

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

int main() {
  ll n;
  cin >> n;
  ll x[200000];
  ll orig[200000];
  rep(i, n) {
    cin >> x[i];
    orig[i] = x[i];
  }
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      if (x[j] > x[i])
        swap(x[j], x[i]);
    }
  }

  ll midf = x[n / 2 - 1];
  ll midb = x[n / 2];
  rep(i, n) {
    if (orig[i] >= midf)
      cout << midb << endl;
    else
      cout << midf << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

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

int main() {
  ll n;
  cin >> n;
  ll x[200000];
  ll orig[200000];
  rep(i, n) {
    cin >> x[i];
    orig[i] = x[i];
  }
  sort(x, x + n, greater<ll>());
  ll midf = x[n / 2 - 1];
  ll midb = x[n / 2];
  rep(i, n) {
    if (orig[i] >= midf)
      cout << midb << endl;
    else
      cout << midf << endl;
  }

  return 0;
}