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 Ruby (2.3.3) (judge verdict: Wrong Answer)

def isOk(arr, index, key)
    arr[index] >= key ? true : false
end

def binarySearchIndex(arr, key)
    left = -1
    right = arr.size
    while (right-left).abs > 1 do
        mid = (right + left) / 2
        if isOk(arr, mid, key) then
            right = mid
        else
            left = mid
        end
    end
    right
end

def msort(a)
    l = a.size
    if l <= 1 then
        return a
    end
    al = msort(a[0..((l-1)/2)])
    ar = msort(a[((l+1)/2)..(l-1)])
    i = 0
    while i < l do
        if al[0] < ar[0] then
            a[i] = al.shift
        else
            a[i] = ar.shift
        end
        i += 1
        if al.size == 0 then
            while i < l do
                a[i] = ar.shift
                i += 1
            end
        elsif ar.length == 0
            while i < l do
                a[i] = al.shift
                i += 1
            end
        end
    end
    return a
end

def main(median, x)
    sortArray = msort(x)
    x.each do |i|
        dummy = sortArray.dup
        dummy.delete_at(binarySearchIndex(sortArray, i))
        puts dummy[median]
    end 
end

median = (gets.chomp.to_i) / 2 - 1
x = gets.chomp.split(" ").map(&:to_i)
main(median, x)