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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n, x[111111], a[111111];
  cin >> n;

  rep(i, n) {
    cin >> x[i];
    a[i] = x[i];
  }
  sort(a, a + n);
  rep(i, n) {
    if (a[(n + 1) / 2] > x[i])
      cout << a[(n + 1) / 2] << endl;
    else
      cout << a[(n + 1) / 2 - 1] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
// typedef long long int ll;
signed main() {

  int n, x[111111 * 2], a[111111 * 2];
  cin >> n;

  rep(i, n) {
    cin >> x[i];
    a[i] = x[i];
  }
  sort(a, a + n);
  rep(i, n) {
    if (a[(n + 1) / 2] > x[i])
      cout << a[(n + 1) / 2] << endl;
    else
      cout << a[(n + 1) / 2 - 1] << endl;
  }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
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;
}
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), a(n);
  for (auto &i : x)
    cin >> i;
  a = x;
  sort(a.begin(), a.end());
  rep(i, n) {
    vector<int> tmp(n);
    tmp = a;
    tmp.erase(lower_bound(tmp.begin(), tmp.end(), x[i]));
    cout << tmp[n / 2 - 1] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
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;
}
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), a(n);
  for (auto &i : x)
    cin >> i;
  a = x;
  sort(a.begin(), a.end());
  rep(i, n) {
    if (a[n / 2] > x[i])
      cout << a[n / 2] << endl;
    else
      cout << a[n / 2 - 1] << endl;
  }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printVec(v)                                                            \
  printf("{");                                                                 \
  for (const auto &i : v) {                                                    \
    std::cout << i << ", ";                                                    \
  }                                                                            \
  printf("}\n");
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;
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;

// cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> sorted = a;
  sort(sorted.begin(), sorted.end());
  for (auto v : a) {
    vector<int> tmp = sorted;
    tmp.erase(lower_bound(tmp.begin(), tmp.end(), v));
    cout << tmp[(n / 2) - 1] << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printVec(v)                                                            \
  printf("{");                                                                 \
  for (const auto &i : v) {                                                    \
    std::cout << i << ", ";                                                    \
  }                                                                            \
  printf("}\n");
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;
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;

// cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> sorted = a;
  sort(sorted.begin(), sorted.end());
  for (auto v : a) {
    if (v <= sorted[n / 2 - 1]) {
      cout << sorted[n / 2] << endl;
    } else {
      cout << sorted[n / 2 - 1] << endl;
    }
  }
  return 0;
}
Problem p03379 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y;
  for (auto &&i : x)
    cin >> i;
  x = y;
  sort(y.rbegin(), y.rend());
  int L = y[n / 2 - 1], R = y[n / 2];
  for (int i = 0; i < n; i++) {
    if (x[i] >= L)
      cout << R << endl;
    else
      cout << L << endl;
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y;
  for (auto &&i : x)
    cin >> i;
  y = x;
  sort(y.rbegin(), y.rend());
  int L = y[n / 2 - 1], R = y[n / 2];
  for (int i = 0; i < n; i++) {
    if (x[i] >= L)
      cout << R << endl;
    else
      cout << L << endl;
  }

  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
int n, x[200005], a[200005], pos[200005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    a[i] = x[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; i++)
    pos[a[i]] = i;
  int l = n / 2 - 1;
  for (int i = 0; i < n; i++) {
    if (pos[x[i]] <= l)
      cout << a[l + 1] << "\n";
    else
      cout << a[l] << "\n";
  }
  re 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
int n, x[200005], a[200005];
map<int, int> pos;
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    a[i] = x[i];
  }
  sort(a, a + n);
  reverse(a, a + n);
  for (int i = 0; i < n; i++)
    pos[a[i]] = i;
  int l = n / 2 - 1;
  for (int i = 0; i < n; i++) {
    if (pos[x[i]] <= l)
      cout << a[l + 1] << "\n";
    else
      cout << a[l] << "\n";
  }
  re 0;
}
Problem p03379 (C++)

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

int n;
// vector<int> x;
// vector<pair<int,int>> y;
// vector<int> b;
int x[200000];
pair<int, int> y[20000];
int b[200000];

int main() {
  cin >> n;
  // x.resize(n);
  // y.resize(n);
  // b.resize(n);
  rep(i, n) {
    cin >> x[i];
    y[i] = make_pair(x[i], i);
  }
  // sort(y.begin(), y.end());
  sort(y, y + n);
  rep(i, n) {
    if (i < n / 2) {
      b[y[i].second] = y[n / 2].first;
    } else {
      b[y[i].second] = y[n / 2 - 1].first;
    }
  }
  rep(i, n) { cout << b[i] << endl; }
}

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

int n;
// vector<int> x;
// vector<pair<int,int>> y;
// vector<int> b;
int x[200000];
pair<int, int> y[200000];
int b[200000];

int main() {
  cin >> n;
  // x.resize(n);
  // y.resize(n);
  // b.resize(n);
  rep(i, n) {
    cin >> x[i];
    y[i] = make_pair(x[i], i);
  }
  // sort(y.begin(), y.end());
  sort(y, y + n);
  rep(i, n) {
    if (i < n / 2) {
      b[y[i].second] = y[n / 2].first;
    } else {
      b[y[i].second] = y[n / 2 - 1].first;
    }
  }
  rep(i, n) { cout << b[i] << endl; }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
using namespace std;
#define fup(i, a, b) for (int i = a; i <= b; ++i)

int x[20004], y[20004];
void Main() {
  int n, nn;
  scanf("%d", &n);
  nn = n / 2;
  fup(i, 1, n) scanf("%d", &x[i]), y[i] = x[i];
  sort(y, y + 1 + n);
  int t = y[nn], tz = y[nn - 1], ty = y[nn + 1], sz = 0, sy = 0;
  {
    int i = nn, j = nn;
    while (y[--i] == t)
      ++sz;
    while (y[++j] == t)
      ++sy;
  }
  if (sz && sy)
    fup(i, 1, n) printf("%d\n", t);
  else if (!sz && sy)
    fup(i, 1, n) printf("%d\n", t);
  else if (sz && !sy)
    fup(i, 1, n) {
      if (x[i] <= t)
        printf("%d\n", ty);
      else
        printf("%d\n", t);
    }
  else
    fup(i, 1, n) {
      if (x[i] <= t)
        printf("%d\n", ty);
      else
        printf("%d\n", t);
    }
}
int main() {
  Main();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
using namespace std;
#define fup(i, a, b) for (int i = a; i <= b; ++i)

int x[200004], y[200004];
void Main() {
  int n, nn;
  scanf("%d", &n);
  nn = n / 2;
  fup(i, 1, n) scanf("%d", &x[i]), y[i] = x[i];
  sort(y, y + 1 + n);
  int t = y[nn], tz = y[nn - 1], ty = y[nn + 1], sz = 0, sy = 0;
  {
    int i = nn, j = nn;
    while (y[--i] == t)
      ++sz;
    while (y[++j] == t)
      ++sy;
  }
  if (sz && sy)
    fup(i, 1, n) printf("%d\n", t);
  else if (!sz && sy)
    fup(i, 1, n) printf("%d\n", t);
  else if (sz && !sy)
    fup(i, 1, n) {
      if (x[i] <= t)
        printf("%d\n", ty);
      else
        printf("%d\n", t);
    }
  else
    fup(i, 1, n) {
      if (x[i] <= t)
        printf("%d\n", ty);
      else
        printf("%d\n", t);
    }
}
int main() {
  Main();
  return 0;
}
Problem p03379 (C++)

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

int popcount(int n) { return __builtin_popcount(n); }

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

  for (int i = 0; i < n; i++) {
    a = init_a;
    a.erase(a.begin() + i);
    sort(a.rbegin(), a.rend());
    cout << a[n / 2 - 1] << endl;
  }
}

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

int popcount(int n) { return __builtin_popcount(n); }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> init_a(n);
  rep(i, n) {
    cin >> a[i];
    init_a[i] = a[i];
  }
  sort(a.rbegin(), a.rend());
  int m1 = a[n / 2 - 1];
  int m2 = a[n / 2];
  a = init_a;
  rep(i, n) {
    if (m1 > a[i])
      cout << m1 << endl;
    else
      cout << m2 << endl;
  }
}
Problem p03379 (Python)

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

cs = x_sorted[n // 2 - 1]
cb = x_sorted[n // 2]

for i, v in enumerate(x):
    if x_sorted.index(v) < n // 2:
        print(cb)
    else:
        print(cs)


Fixed submission:
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)

cs = x_sorted[n // 2 - 1]
cb = x_sorted[n // 2]

for i, v in enumerate(x):
    if v <= cs:
        print(cb)
    else:
        print(cs)
Problem p03379 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x: x[1], reverse=True)
    idx = N // 2 - 1
    result = [False for _ in range(N)]
    for n, item in enumerate(Xi):
        i = item[0]
        xi = Xi[:n] + Xi[n + 1 :]
        result[i] = xi[idx][1]
    for x in result:
        print(x)


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x: x[1], reverse=True)
    result = list(range(N))
    index = N // 2 - 1
    for i in range(N):
        idx = index
        if i <= index:
            idx += 1
        result[Xi[i][0]] = Xi[idx][1]

    for x in result:
        print(x)


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

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

c = (n - 1) // 2

for i in range(len(x)):
    x2 = x.copy()
    x2.pop(i)
    x2.sort()
    print(x2[c])


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

x2 = x.copy()
x2.sort()
c1 = x2[n // 2 - 1]
c2 = x2[n // 2]
for i in x:
    if c1 >= i:
        print(c2)
    else:
        print(c1)
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
const int MOD = 1000000007;

ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int z;
    cin >> z;
    a.push_back(z);
    b.push_back(z);
  }
  sort(b.begin(), b.end());

  int right = b[n / 2 - 1];
  int left = b[n / 2];
  for (int i = 0; i < n; i++) {
    if (a[i] < b[right]) {
      cout << left << endl;
    } else {
      cout << right << endl;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
const int MOD = 1000000007;

ll GCD(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

int main() {
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int z;
    cin >> z;
    a.push_back(z);
    b.push_back(z);
  }
  sort(b.begin(), b.end());

  int right = b[n / 2 - 1];
  int left = b[n / 2];
  for (int i = 0; i < n; i++) {
    if (a[i] < b[n / 2]) {
      cout << left << endl;
    } else {
      cout << right << endl;
    }
  }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  int N;
  cin >> N;
  ll X[N + 1], P, Q;
  vector<ll> L;
  for (int i = 1; i <= N; ++i) {
    cin >> X[i];
    L.push_back(X[i]);
  }
  SORT(L);
  P = L.at(N / 2);
  Q = L.at(N / 2 + 1);
  RREP(i, N) {
    if (X[i] <= P)
      cout << Q << endl;
    else
      cout << P << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int main() {
  int N;
  cin >> N;
  ll X[N + 1], P, Q;
  vector<ll> L;
  for (int i = 1; i <= N; ++i) {
    cin >> X[i];
    L.push_back(X[i]);
  }
  SORT(L);
  P = L.at(N / 2 - 1);
  Q = L.at(N / 2);
  RREP(i, N) {
    if (X[i] <= P)
      cout << Q << endl;
    else
      cout << P << endl;
  }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> value_index; // (value, index)
  for (int i = 0; i < n; i++) {
    pair<int, int> vi;
    cin >> vi.first;
    vi.second = i;
    value_index.push_back(vi);
  }

  /*for(int i = 0; i < value_index.size(); i++){
      cout << "(" << value_index[i].first << ", " << value_index[i].second <<
  ")" << endl;
  }*/

  // cout << endl;
  sort(value_index.begin(), value_index.end());

  /*for(int i = 0; i < value_index.size(); i++){
      cout << "(" << value_index[i].first << ", " << value_index[i].second <<
  ")" << endl;
  }*/

  vector<int> medians_vec(n, 0);
  for (int i = 0; i < n; i++) {
    vector<pair<int, int>> value_index_copy(value_index);
    int medIndex = value_index_copy[i].second;
    value_index_copy.erase(value_index_copy.begin() + i);
    medians_vec[medIndex] = value_index_copy[n / 2 - 1].first;
  }

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

  //    int ans = min(charge1, charge2);
  //    cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> value_index; // (value, index)
  for (int i = 0; i < n; i++) {
    pair<int, int> vi;
    cin >> vi.first;
    vi.second = i;
    value_index.push_back(vi);
  }

  /*for(int i = 0; i < value_index.size(); i++){
      cout << "(" << value_index[i].first << ", " << value_index[i].second <<
  ")" << endl;
  }*/

  // cout << endl;
  sort(value_index.begin(), value_index.end());

  /*for(int i = 0; i < value_index.size(); i++){
      cout << "(" << value_index[i].first << ", " << value_index[i].second <<
  ")" << endl;
  }*/

  vector<int> medians_vec(n, 0);
  for (int i = 0; i < n; i++) {
    int medIndex = value_index[i].second;
    int viIndex = (i < n / 2) ? n / 2 : n / 2 - 1;
    medians_vec[medIndex] = value_index[viIndex].first;
  }

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

  //    int ans = min(charge1, charge2);
  //    cout << ans << endl;
  return 0;
}
Problem p03379 (C++)

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

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

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  int G1 = b[n / 2 - 1], G2 = b[n / 2];
  for (int i = 0; i < n; i++) {
    if (G2 <= a[i])
      cout << G1 << endl;
    else
      cout << G2 << endl;
  }
  return 0;
}

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

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

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  int G1 = b[n / 2 - 1], G2 = b[n / 2];
  for (int i = 0; i < n; i++) {
    if (G2 <= a[i])
      cout << G1 << endl;
    else
      cout << G2 << endl;
  }
  return 0;
}
Problem p03379 (C++)

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

int main(void) {
  int n;
  scanf("%d", &n);
  int x[n], l[n];
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &(x[i]));
    l[i] = x[i];
  }
  sort(l, l + n);
  for (size_t i = 0; i < n; i++) {
    int out = x[i];
    for (size_t j = 0; j < n; j++) {
      if (out == l[j]) {
        printf("%d\n", j < n / 2 ? l[n / 2] : l[(n / 2) - 1]);
        break;
      }
    }
  }
  return 0;
}

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

int main(void) {
  int n;
  scanf("%d", &n);
  int x[n], l[n];
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &(x[i]));
    l[i] = x[i];
  }
  sort(l, l + n);
  for (size_t i = 0; i < n; i++) {
    printf("%d\n", x[i] < l[n / 2] ? l[n / 2] : l[(n / 2) - 1]);
  }
  return 0;
}
Problem p03379 (C++)

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

using namespace std;

int X[200010];
int Y[200010];

int main() {
  int N;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    Y[i] = X[i];
  }

  // std::sort(&X[0], &X[N-1]);
  std::sort(X, X + N);
  int left = (N - 1) / 2;
  int right = left + 1;
  for (int j = 0; j < N; j++) {
    auto ret = std::find(X, X + N, Y[j]);
    size_t i = std::distance(X, ret);
    if (i <= left)
      cout << X[right] << endl;
    else if (i >= right)
      cout << X[left] << endl;
  }
}

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

using namespace std;

int X[200010];
int Y[200010];

int main() {
  int N;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> X[i];
    Y[i] = X[i];
  }

  // std::sort(&X[0], &X[N-1]);
  std::sort(X, X + N);
  int left = (N - 1) / 2;
  int right = left + 1;
  for (int j = 0; j < N; j++) {
    // auto ret = std::find(X, X+N, Y[j]);
    // size_t i = std::distance(X, ret);
    int i = std::lower_bound(X, X + N, Y[j]) - X;
    if (i <= left)
      cout << X[right] << endl;
    else if (i >= right)
      cout << X[left] << endl;
  }
}
Problem p03379 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (auto &i : x)
    cin >> i;
  vector<int> asc(n);
  asc = x;
  sort(asc.begin(), asc.end());
  /*double med = ((long long)asc[n/2-1] + (long long)asc[n/2]) / 2.0;
  for (int i: x) {
      if (i > med) cout << asc[n/2-1] << endl;
      else if (i < med) cout << asc[n/2] << endl;
      else cout << med << endl;
  }*/
  int med1 = asc[n / 2 - 1], med2 = asc[n / 2];
  for (int i : x) {
    if (x[i] < med2)
      cout << med2 << endl;
    else
      cout << med1 << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (auto &i : x)
    cin >> i;
  vector<int> asc(n);
  asc = x;
  sort(asc.begin(), asc.end());
  /*double med = ((long long)asc[n/2-1] + (long long)asc[n/2]) / 2.0;
  for (int i: x) {
      if (i > med) cout << asc[n/2-1] << endl;
      else if (i < med) cout << asc[n/2] << endl;
      else cout << med << endl;
  }*/
  int med1 = asc[n / 2 - 1], med2 = asc[n / 2];
  for (int i : x) {
    if (i < med2)
      cout << med2 << endl;
    else
      cout << med1 << endl;
  }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, c, x, y;
  int a[n], b[n];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(a, a + n);
  x = a[n / 2 - 1];
  y = a[n / 2];

  for (int i = 0; i < n; i++) {
    if (b[i] <= x)
      printf("%d\n", y);
    else
      printf("%d\n", x);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
  int n, c, x, y;
  int a[200000], b[200000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(a, a + n);
  x = a[n / 2 - 1];
  y = a[n / 2];

  for (int i = 0; i < n; i++) {
    if (b[i] <= x)
      printf("%d\n", y);
    else
      printf("%d\n", x);
  }
  return 0;
}
Problem p03379 (C++)

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

int main() {
  int n, i, a, x = 0, cnt = 0;
  scanf("%d", &n);
  int sz[n], b[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &sz[i]);
    b[i] = sz[i];
  }
  a = 0;
  sort(b, b + n);
  for (i = 0; i < n; i++) {
    // printf("%d ",x);
    if (b[i] != sz[a] || cnt != 0) {
      x++;
    } else
      cnt++;

    //   printf("sz[a]=%d b[i]=%d i=%d x=%d sz[i]=%d\n",sz[a],b[i],i,x,sz[i]);
    if (a == n)
      break;
    if (x == n / 2) {
      printf("%d\n", b[i]);
      a++;
      i = -1;
      x = 0;
      cnt = 0;
    }
  }
  return 0;
}


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

int main() {
  int n, i, a, x = 0, cnt = 0;
  scanf("%d", &n);
  int sz[n], b[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &sz[i]);
    b[i] = sz[i];
  }
  a = 0;
  sort(b, b + n);
  for (i = 0; i < n; i++) {
    // printf("sz[i]=%db[n/2+1]%d ",sz[i],b[n/2+1]);
    if (sz[i] < b[n / 2])
      printf("%d\n", b[n / 2]);
    else {
      printf("%d\n", b[n / 2 - 1]);
    }
  }
  return 0;
}
Problem p03379 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    X = list(map(int, input().split()))
    for i in range(N):
        tmp = X[:i]
        tmp.extend(X[i + 1 :])
        tmp.sort()
        print(tmp[N // 2 - 1])


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X)[N // 2 - 1 : N // 2 + 1]
    for i in X:
        print(x[i <= x[0]])


if __name__ == "__main__":
    main()
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, m, n) for (int i = m; i < (int)(n); i++)
const int inf = 10e9 + 7;
using namespace std;
int a[100010];
int b[100010];
signed main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  rep(i, n) {
    if (a[i] <= b[n / 2 - 1])
      cout << b[n / 2] << endl;
    else {
      cout << b[n / 2 - 1] << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, m, n) for (int i = m; i < (int)(n); i++)
const int inf = 10e9 + 7;
using namespace std;
int a[200010];
int b[200010];
signed main() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  rep(i, n) {
    if (a[i] <= b[n / 2 - 1])
      cout << b[n / 2] << endl;
    else {
      cout << b[n / 2 - 1] << endl;
    }
  }
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main() {
  int n;
  vi x(n);
  rep(i, n) cin >> x[i];
  vi y = x;
  sort(all(y));
  int low = y.at(n / 2 - 1);
  int high = y.at(n / 2);
  rep(i, n) {
    if (x[i] <= low)
      cout << high << endl;
    else
      cout << low << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, t) for (int i = s; i < t; i++)
#define RNG(i, s, t, u) for (int i = s; i < t; i += u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

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

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

int main() {
  int n;
  int tmp, tmp2;
  cin >> n;
  long long int x[n], y[n];
  long long int ans[n];
  long long min;

  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < n; i++)
    y[i] = x[i];

  for (int i = 0; i < n / 2 + 1; i++) {
    min = i;
    for (int j = i; j < n; j++) {
      if (x[min] > x[j])
        min = j;
    }
    tmp = x[min];
    x[min] = x[i];
    x[i] = tmp;
  }

  for (int i = 0; i < n; i++) {
    tmp = 0;
    if (y[i] >= x[n / 2 + tmp])
      tmp = -1;
    cout << x[n / 2 + tmp] << endl;
  }
}

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

int main() {
  int n;
  int tmp, tmp2;
  cin >> n;
  long long int x[n], y[n];
  long long int ans[n];
  long long min;

  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < n; i++)
    y[i] = x[i];

  // for(int i=0;i<n/2+1;i++){
  //   min = 0;
  //   for(int j=0;j<n;j++){
  //     if(min>x[j])min=j;
  //   }
  //   tmp=x[min];
  //   x[min]=x[i];
  //   x[i]=tmp;
  // }
  sort(x, x + n);

  for (int i = 0; i < n; i++) {
    tmp = 0;
    if (y[i] >= x[n / 2 + tmp])
      tmp = -1;
    cout << x[n / 2 + tmp] << endl;
  }
}
Problem p03379 (C++)

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

using namespace std;

long int MAX_N = 200000;
long int MAX_X = 1000000000;

int main(int argc, char const *argv[]) {
  long int N;
  long int x[MAX_N];

  cin >> N;
  vector<pair<long int, long int>> v(N);

  for (long int i = 0; i < N; i++) {
    cin >> x[i];
    v[i] = make_pair(x[i], i);
  }

  int l = N / 2;

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

  for (long int j = 0; j < N; j++) {
    for (long int i = 0; i < N; i++) {
      if (v[i].second == j) {
        if (v[i].first < v[l - 1].first)
          cout << v[l].first << endl;
        else if (v[i].first == v[l - 1].first)
          cout << v[l].first << endl;
        else
          cout << v[l - 1].first << endl;
        break;
      }
    }
  }

  return 0;
}


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

using namespace std;

long int MAX_N = 200000;
long int MAX_X = 1000000000;

int main(int argc, char const *argv[]) {
  long int N;
  long int x[MAX_N];

  cin >> N;
  vector<pair<long int, long int>> v(N);

  for (long int i = 0; i < N; i++) {
    cin >> x[i];
    v[i] = make_pair(x[i], i);
  }

  int l = N / 2;

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

  long int idx[MAX_N];

  for (int i = 0; i < N; i++)
    idx[v[i].second] = i;

  for (long int i = 0; i < N; i++) {
    if (v[idx[i]].first < v[l - 1].first)
      cout << v[l].first << endl;
    else if (v[idx[i]].first == v[l - 1].first)
      cout << v[l].first << endl;
    else
      cout << v[l - 1].first << endl;
  }

  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long

signed main() {
  int n;
  cin >> n;
  pair<int, int> a[200050];
  rep(i, n) {
    int b;
    cin >> b;
    a[i] = make_pair(b, i);
  }
  sort(a, a + n);
  int ansmx = a[(n - 1) / 2].fst;
  int ansmn = a[n / 2].fst;
  int ans[100050];
  rep(i, n) {
    if (i < ((n + 1) / 2)) {
      ans[a[i].scd] = ansmn;
    } else {
      ans[a[i].scd] = ansmx;
    }
  }
  rep(i, n) { cout << ans[i] << endl; }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long

signed main() {
  int n;
  cin >> n;
  pair<int, int> a[200050];
  rep(i, n) {
    int b;
    cin >> b;
    a[i] = make_pair(b, i);
  }
  sort(a, a + n);
  int ansmx = a[(n - 1) / 2].fst;
  int ansmn = a[n / 2].fst;
  int ans[300050];
  rep(i, n) {
    if (i < ((n + 1) / 2)) {
      ans[a[i].scd] = ansmn;
    } else {
      ans[a[i].scd] = ansmx;
    }
  }
  rep(i, n) { cout << ans[i] << endl; }

  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX / 2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// functions
bool second_smaller(const pii &left, const pii &right) {
  return left.second < right.second;
}
#endif

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

  int N;
  cin >> N;
  vi X(N);
  REP(i, N) cin >> X[i];

  vector<pii> v;
  REP(i, N) v.push_back(pii(i, X[i]));
  sort(v.begin(), v.end(), second_smaller);

  map<int, int> mp;
  REP(i, N) mp[v[i].first] = i;

  vi y;
  REP(i, N) y.push_back(v[i].second);

  vi ans;
  REP(i, N) {
    vi t = y;
    t.erase(t.begin() + mp[i]);
    ans.push_back(t[N / 2 - 1]);
  }

  for (int i : ans)
    cout << i << endl;

  return 0;
}

Fixed submission:
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX / 2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// functions
bool second_smaller(const pii &left, const pii &right) {
  return left.second < right.second;
}
#endif

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

  int N;
  cin >> N;
  vi X(N);
  REP(i, N) cin >> X[i];

  vector<pii> v;
  REP(i, N) v.push_back(pii(i, X[i]));
  sort(v.begin(), v.end(), second_smaller);

  map<int, int> mp;
  REP(i, N) mp[v[i].first] = i;

  vi y;
  REP(i, N) y.push_back(v[i].second);

  vi ans;
  REP(i, N) {
    int di = mp[i];
    if (di < N / 2)
      ans.push_back(y[N / 2]);
    else
      ans.push_back(y[N / 2 - 1]);
  }

  for (int i : ans)
    cout << i << endl;

  return 0;
}
Problem p03379 (C++)

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

int main() {
  int n;
  cin >> n;
  int a[NUM] = {0};
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int v[NUM] = {0};
  copy(a, a + n + 1, v);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (v[i] > a[n / 2])
      cout << a[n / 2] << endl;
    else
      cout << a[(n / 2) + 1] << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#define NUM 200003
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[NUM] = {0};
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int v[NUM] = {0};
  copy(a, a + n + 1, v);
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (v[i] > a[n / 2])
      cout << a[n / 2] << endl;
    else
      cout << a[(n / 2) + 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;
  int s = 0;
  vector<int> v;
  cin >> n;

  int A[n];

  for (int i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
    A[i] = s;
  }

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

  for (int i = 0; i < n; i++) {
    decltype(v)::iterator it = lower_bound(v.begin(), v.end(), A[i]);
    v.erase(it);
    cout << v[(0 + n - 1) / 2] << endl;
    v.insert(it, A[i]);
  }

  return 0;
}

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

int main() {
  int n;
  int s = 0;
  vector<int> v;
  cin >> n;

  int A[n];

  for (int i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
    A[i] = s;
  }

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

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

  return 0;
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int c[n];
  for (int i = 0; i < n; i++) {
    for (int i = 0; i < n; i++) {
      c[i] = x[i];
    }
    c[i] = 0;
    sort(c, c + n);
    cout << c[n / 2] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int c[n];
  for (int i = 0; i < n; i++) {
    c[i] = x[i];
  }
  sort(c, c + n);
  int ml = c[n / 2 - 1];
  int mr = c[n / 2];
  for (int i = 0; i < n; i++) {
    if (x[i] < mr)
      cout << mr << endl;
    else
      cout << ml << endl;
  }
  return 0;
}
Problem p03379 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    long x;
    cin >> x;
    xs[i] = x;
  }
  for (int i = 0; i < n; i++) {
    vector<int> temp;
    temp.insert(temp.end(), xs.begin(), xs.begin() + i);
    temp.insert(temp.end(), xs.begin() + i + 1, xs.end());
    sort(temp.begin(), temp.end());
    cout << temp[n / 2 - 1] << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    long x;
    cin >> x;
    xs[i] = x;
  }
  vector<int> temp;
  temp.insert(temp.begin(), xs.begin(), xs.end());
  sort(temp.begin(), temp.end());
  int mid = temp[n / 2];
  for (int x : xs) {
    if (x < mid) {
      cout << mid << endl;
    } else {
      cout << temp[n / 2 - 1] << endl;
    }
  }
}
Problem p03379 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

#define SORT(arr) sort(arr, arr + ARRAY_LENGTH(arr))

int N;
int bucket[200001] = {0};
int main() {
  cin >> N;
  int a[N], b[N];
  int mi = (N - 1) / 2;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  SORT(b);
  int md0 = b[mi + 1], md1 = b[mi];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (a[i] == b[j]) {
        if (j >= mi + 1) {
          cout << md1 << endl;
          break;
        } else {
          cout << md0 << endl;
          break;
        }
      }
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

#define SORT(arr) sort(arr, arr + ARRAY_LENGTH(arr))

int N;
int bucket[200001] = {0};
int main() {
  cin >> N;
  int a[N], b[N];
  int mi = (N - 1) / 2;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  SORT(b);
  int md0 = b[mi + 1], md1 = b[mi];

  for (int i = 0; i < N; i++) {
    if (a[i] < md0)
      cout << md0 << endl;
    else
      cout << md1 << endl;
  }

  return 0;
}
Problem p03379 (C++)

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

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

  vector<int> X(N);
  vector<int> sortX(N);

  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    X.at(i) = x;
    sortX.at(i) = X.at(i);
  }

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

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (X.at(i) == sortX.at(j)) {
        X.at(i) = j;
        break;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (X.at(i) < N / 2)
      cout << sortX.at(N / 2) << endl;
    else
      cout << sortX.at(N / 2 - 1) << endl;
  }
}

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

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

  vector<int> X(N);
  vector<int> sortX(N);

  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    X.at(i) = x;
    sortX.at(i) = X.at(i);
  }

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

  for (int i = 0; i < N; i++) {
    if (sortX.at(N / 2 - 1) >= X.at(i))
      cout << sortX.at(N / 2) << endl;
    else
      cout << sortX.at(N / 2 - 1) << endl;
  }
}
Problem p03380 (C++)

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

int main() {
  int n, best;
  vector<int> a(10000);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  best = 1;
  for (int i = 2; i < n; i++) {
    if (abs((double)(a.at(best)) - (double)(a.at(0)) / 2) >
        abs((double)(a.at(i)) - (double)(a.at(0)) / 2)) {
      best = i;
    }
  }
  cout << a.at(0) << " " << a.at(best) << endl;
}

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

int main() {
  int n, best;
  vector<int> a(100000);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  best = 1;
  for (int i = 2; i < n; i++) {
    if (abs((double)(a.at(best)) - (double)(a.at(0)) / 2) >
        abs((double)(a.at(i)) - (double)(a.at(0)) / 2)) {
      best = i;
    }
  }
  cout << a.at(0) << " " << a.at(best) << endl;
}
Problem p03380 (C++)

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  long m(numeric_limits<long>::min()), maxdex(-1), c(0);
  for (auto &i : A) {
    scanf("%ld", i);
    if (m < i) {
      m = i;
      maxdex = c;
    }
    ++c;
  }
  swap(A[N - 1], A[maxdex]);
  nth_element(A.begin(), A.begin(), A.end() - 1,
              [&m](auto a, auto b) { return a * (a - m) < b * (b - m); });
  cout << A[N - 1] << " " << A[0] << endl;
}

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  long m(numeric_limits<long>::min()), maxdex(-1), c(0);
  for (auto &i : A) {
    scanf("%ld", &i);
    if (m < i) {
      m = i;
      maxdex = c;
    }
    ++c;
  }
  swap(A[N - 1], A[maxdex]);
  nth_element(A.begin(), A.begin(), A.end() - 1,
              [&m](auto a, auto b) { return a * (a - m) < b * (b - m); });
  cout << A[N - 1] << " " << A[0] << endl;
}
Problem p03380 (C++)

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

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

  int a[10001];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ma = 0;

  for (int i = 0; i < n - 1; i++) {
    int temp = (a[n - 1] + 1) / 2;
    if (a[i] > temp) {
      if (temp - a[i - 1] <= a[i] - temp)
        ma = a[i - 1];
      else
        ma = a[i];
      break;
    }
  }

  cout << a[n - 1] << ' ' << ma << endl;
  return 0;
}


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

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

  int a[1000001];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ma = 0;

  for (int i = 0; i < n - 1; i++) {
    int temp = (a[n - 1] + 1) / 2;
    if (a[i] > temp) {
      if (temp - a[i - 1] <= a[i] - temp)
        ma = a[i - 1];
      else
        ma = a[i];
      break;
    }
  }

  cout << a[n - 1] << ' ' << ma << endl;
  return 0;
}