C - Many Medians 解説 /

実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 300

問題文

l が奇数のとき,l 個の数 a_1, a_2, ..., a_l の中央値とは,a_1, a_2, ..., a_l の中で \frac{l+1}{2} 番目に大きい値のことを言います.

N 個の数 X_1, X_2, ..., X_N が与えられます.ここで,N は偶数です. i = 1, 2, ..., N に対して,X_1, X_2, ..., X_N から X_i のみを除いたもの,すなわち X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N の中央値を B_i とします.

i = 1, 2, ..., N に対して,B_i を求めてください.

制約

  • 2 \leq N \leq 200000
  • N は偶数
  • 1 \leq X_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
X_1 X_2 ... X_N

出力

N 行出力せよ. i 行目には B_i を出力せよ.


入力例 1

4
2 4 4 3

出力例 1

4
3
3
4
  • X_2, X_3, X_4 の中央値は 4 なので,B_1 = 4 です.
  • X_1, X_3, X_4 の中央値は 3 なので,B_2 = 3 です.
  • X_1, X_2, X_4 の中央値は 3 なので,B_3 = 3 です.
  • X_1, X_2, X_3 の中央値は 4 なので,B_4 = 4 です.

入力例 2

2
1 2

出力例 2

2
1

入力例 3

6
5 5 4 4 3 3

出力例 3

4
4
4
4
4
4

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