Problem:
Score : 300 points

Problem Statement

When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.

You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.

Find B_i for each i = 1, 2, ..., N.

Constraints

2 \leq N \leq 200000

N is even.

1 \leq X_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print N lines.
The i-th line should contain B_i.

Sample Input 1

4
2 4 4 3

Sample Output 1

4
3
3
4

Since the median of X_2, X_3, X_4 is 4, B_1 = 4.

Since the median of X_1, X_3, X_4 is 3, B_2 = 3.

Since the median of X_1, X_2, X_4 is 3, B_3 = 3.

Since the median of X_1, X_2, X_3 is 4, B_4 = 4.

Sample Input 2

2
1 2

Sample Output 2

2
1

Sample Input 3

6
5 5 4 4 3 3

Sample Output 3

4
4
4
4
4
4

Solution in C (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

/*

import "core"
import "procon"

type Data {
  index Int
  value Int
}

var xs Array[200000, Int]
var sorted Array[200000, Data]

fn bubblesort(len Int) {
  for i in range(0, len-1) {
    j := len - 1
    while (j > i) {
      if (get(sorted, j).value < get(sorted, j-1).value) {
        tmp := get(sorted, j)
        a := get(sorted, j-1)
        set(sorted, j, a)
        set(sorted, j-1, tmp)
      }
      j -= 1
    }
  }
}

fn main() {
  n := read_int()
  for i in range(0, n-1) {
    set(xs, i, read_int())
    set(sorted, i, init(Data){i; get(xs, i)})
  }

  bubblesort(n)
  cil := cast[Int](n / 2) - 1
  cir := cast[Int](n / 2)
  l := get(sorted, cil)
  r := get(sorted, cir)
  for i in range(0, n-1) {
    if (l.index != i && get(xs, i) < l.value) {
      println(r.value)
    } elif (l.index != i) {
      println(l.value)
    } elif (r.index != i && get(xs, i) > r.value) {
      println(l.value)
    } else {
      println(r.value)
    }
  }
}

main()

*/
#include "stdbool.h"
#include "stdint.h"
bool core_prelude_true;
bool core_prelude_false;
bool core_definitions_is_windows;
bool core_definitions_is_compiletime;
bool core_definitions_is_runtime;
bool core_definitions_is_jscodegen;
#include "math.h"
float core_math_M_PI;
#include "stdio.h"
void* core_pointer_nullGG_() {
void* core_pointer_tmpid39 = ((void*)(0));
return core_pointer_tmpid39;
}
void* core_pointer_null;
char* core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char__core_prelude_Int(char* core_pointer_p, int64_t core_pointer_i) {
char* core_pointer_tmpid40 = ((char*)((((int64_t)(core_pointer_p)) + core_pointer_i)));
return core_pointer_tmpid40;
}
char core_string_getGG_core_prelude_CString_core_prelude_Int(char* core_string_cs, int64_t core_string_i) {
char core_string_tmpid41 = (*(core_pointer_plusexclGcore_prelude_CharG_core_pointer_Ptr_core_prelude_Char__core_prelude_Int(((char*)(core_string_cs)), core_string_i)));
return core_string_tmpid41;
}
#include "string.h"
struct core_string_String {
char* p;
int64_t len;
};
char core_string_charGG_core_prelude_Int(int64_t core_string_c) {
char core_string_tmpid44 = ((char)(core_string_c));
return core_string_tmpid44;
}
char core_string_cr;
char core_string_lf;
#include "inttypes.h"
int64_t procon_read_intGG_() {
int64_t procon_ret;
scanf("%" PRId64, &procon_ret);
int64_t procon_tmpid65 = procon_ret;
return procon_tmpid65;
}
struct Array1024_core_prelude_Char { char data[1024]; };
bool procon_is_debug;
struct c_Data {
int64_t index;
int64_t value;
};
struct Array200000_core_prelude_Int { int64_t data[200000]; };
struct Array200000_core_prelude_Int c_xs;
struct Array200000_c_Data { struct c_Data data[200000]; };
struct Array200000_c_Data c_sorted;
void c_bubblesortGG_core_prelude_Int(int64_t c_len) {
{
int64_t c_i = 0;
while ((c_i <= (c_len - 1))) {
int64_t c_j = (c_len - 1);
while ((c_j > c_i)) {
if ((((&c_sorted)->data[c_j]).value < ((&c_sorted)->data[(c_j - 1)]).value)) {
struct c_Data c_tmp = ((&c_sorted)->data[c_j]);
struct c_Data c_a = ((&c_sorted)->data[(c_j - 1)]);
(&c_sorted)->data[c_j] = c_a;
(&c_sorted)->data[(c_j - 1)] = c_tmp;
} else {}(c_j -= 1);
};
;
(c_i += 1);
};

}
;
;
;
}
void c_mainGG_() {
int64_t c_n = procon_read_intGG_();
{
int64_t c_i = 0;
while ((c_i <= (c_n - 1))) {
(&c_xs)->data[c_i] = procon_read_intGG_();
(&c_sorted)->data[c_i] = (struct c_Data){c_i, ((&c_xs)->data[c_i])};
;
(c_i += 1);
};

}
;
;
;
c_bubblesortGG_core_prelude_Int(c_n);
double __floritmp1 = (((double)(c_n)) / ((double)(2)));
int64_t c_cil = (((int64_t)(__floritmp1)) - 1);
double __floritmp2 = (((double)(c_n)) / ((double)(2)));
int64_t c_cir = ((int64_t)(__floritmp2));
struct c_Data c_l = ((&c_sorted)->data[c_cil]);
struct c_Data c_r = ((&c_sorted)->data[c_cir]);
{
int64_t c_i = 0;
while ((c_i <= (c_n - 1))) {
if (((c_l.index != c_i) && (((&c_xs)->data[c_i]) < c_l.value))) {
printf("%lld", c_r.value);
;
;
printf("%s", "\n");
;
;
;
} else {if ((c_l.index != c_i)) {
printf("%lld", c_l.value);
;
;
printf("%s", "\n");
;
;
;
} else {if (((c_r.index != c_i) && (((&c_xs)->data[c_i]) > c_r.value))) {
printf("%lld", c_l.value);
;
;
printf("%s", "\n");
;
;
;
} else {printf("%lld", c_r.value);
;
;
printf("%s", "\n");
;
;
;
}}};
(c_i += 1);
};

}
;
;
;
}

void flori_main() {
core_prelude_true = 1;
core_prelude_false = 0;
core_definitions_is_windows = 
#ifdef _WIN32
#define is_windows true
#elif _WIN64
#define is_windows true
#else
#define is_windows false
#endif
  is_windows;
core_definitions_is_compiletime = 
#ifdef FLORI_COMPILETIME
#define is_compiletime true
#else
#define is_compiletime false
#endif
  is_compiletime;
core_definitions_is_runtime = !(core_definitions_is_compiletime);
core_definitions_is_jscodegen = 
#ifdef FLORI_JSCODEGEN
#define is_jscodegen true
#else
#define is_jscodegen false
#endif
  is_jscodegen;
core_math_M_PI = M_PI;
core_pointer_null = core_pointer_nullGG_();
core_string_cr = core_string_charGG_core_prelude_Int(13);
core_string_lf = core_string_charGG_core_prelude_Int(10);
procon_is_debug = core_prelude_true;
c_mainGG_();
}
int main(int argc, char** argv) { flori_main(); }