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 Rust (1.15.1) (judge verdict: Runtime Error)

use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct Solver {
    h: usize,
    w: usize,
    field: Vec<Vec<char>>,
    // ycnts: Vec<HashMap<char, usize>>,
    // xcnts: Vec<HashMap<char, usize>>,
    // ycenter: Vec<bool>,
    // xcenter: Vec<bool>,
}

impl Solver {
    fn new() -> Solver {
        let h: usize = read();
        let w: usize = read();
        let mut field = vec![vec![]; h];
        for y in 0..h {
            field[y] = read::<String>().chars().collect::<Vec<_>>();
        }
        // let mut ycnts = vec![HashMap::<char, usize>::new(); h];
        // let mut xcnts = vec![HashMap::<char, usize>::new(); w];
        // let mut ycenter = vec![false; h];
        // let mut xcenter = vec![false; w];
        // for y in 0..h {
        //     for x in 0..w {
        //         let c = field[y][x];
        //         *ycnts[y].entry(c).or_insert(0) += 1;
        //     }
        //     if ycnts[y].values().filter(|v| *v % 2 == 1).count() == w % 2 {
        //         ycenter[y] = true;
        //     }
        // }
        // for x in 0..w {
        //     for y in 0..h {
        //         let c = field[y][x];
        //         *xcnts[x].entry(c).or_insert(0) += 1;
        //     }
        //     if xcnts[x].values().filter(|v| *v % 2 == 1).count() == h % 2 {
        //         xcenter[x] = true;
        //     }
        // }
        Solver {
            h: h,
            w: w,
            field: field,
            // ycnts: ycnts,
            // xcnts: xcnts,
            // ycenter: ycenter,
            // xcenter: xcenter,
        }
    }
    fn is_valid(&self, ypairs: &Vec<(usize, usize)>, xpairs: &Vec<(usize, usize)>) -> bool {
        // println!("{:?} {:?}", ypairs, xpairs);
        for yp in ypairs.iter() {
            for xp in xpairs.iter() {
                if self.field[yp.0][xp.0] != self.field[yp.1][xp.1]
                    || self.field[yp.0][xp.1] != self.field[yp.1][xp.0]
                {
                    return false;
                }
            }
        }
        true
    }
    fn xdfs(
        &self,
        rest: usize,
        ypairs: &Vec<(usize, usize)>,
        xpairs: &mut Vec<(usize, usize)>,
    ) -> bool {
        if rest == 0 {
            return self.is_valid(ypairs, xpairs);
        }
        if xpairs.len() == 0 && self.w % 2 == 1 {
            for x in 0..self.w {
                // if !self.xcenter[x] {
                //     continue;
                // }
                let nrest = rest ^ (1 << x);
                xpairs.push((x, x));
                if self.xdfs(nrest, ypairs, xpairs) {
                    return true;
                }
                xpairs.pop();
            }
        } else {
            let x1 = rest.trailing_zeros() as usize;
            for x2 in x1 + 1..self.w {
                if (rest & (1 << x2)) == 0
                /*|| self.xcnts[x1] != self.xcnts[x2]*/
                {
                    continue;
                }
                // println!("{} {} {}", rest, x1, x2);
                let nrest = rest ^ (1 << x1) ^ (1 << x2);
                assert!(nrest < rest);
                xpairs.push((x1, x2));
                if self.xdfs(nrest, ypairs, xpairs) {
                    return true;
                }
                xpairs.pop();
            }
        }
        false
    }
    fn ydfs(&self, rest: usize, pairs: &mut Vec<(usize, usize)>) -> bool {
        if rest == 0 {
            return self.xdfs((1 << self.w) - 1, pairs, &mut vec![]);
        }
        if pairs.len() == 0 && self.h % 2 == 1 {
            for y in 0..self.h {
                // if !self.ycenter[y] {
                //     continue;
                // }
                let nrest = rest ^ (1 << y);
                pairs.push((y, y));
                if self.ydfs(nrest, pairs) {
                    return true;
                }
                pairs.pop();
            }
        } else {
            let y1 = rest.trailing_zeros() as usize;
            for y2 in y1 + 1..self.h {
                if (rest & (1 << y2)) == 0
                /*|| self.ycnts[y1] != self.ycnts[y2]*/
                {
                    continue;
                }
                // println!("{} {} {}", rest, y1, y2);
                let nrest = rest ^ (1 << y1) ^ (1 << y2);
                assert!(nrest < rest);
                pairs.push((y1, y2));
                if self.ydfs(nrest, pairs) {
                    return true;
                }
                pairs.pop();
            }
        }
        false
    }
    fn solve(&mut self) {
        if self.ydfs((1 << self.h) - 1, &mut vec![]) {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}

fn main() {
    let mut solver = Solver::new();
    solver.solve();
}