Problem:
Score : 600 points

Problem Statement

Given are two sequences A and B, both of length N.
A and B are each sorted in the ascending order.
Check if it is possible to reorder the terms of B so that for each i (1 \leq i \leq N) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it.

Constraints

1\leq N \leq 2 \times 10^5

1\leq A_i,B_i \leq N

A and B are each sorted in the ascending order.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

Output

If there exist no reorderings that satisfy the condition, print No.

If there exists a reordering that satisfies the condition, print Yes on the first line.
After that, print a reordering of B on the second line, separating terms with a whitespace.

If there are multiple reorderings that satisfy the condition, you can print any of them.

Sample Input 1

6
1 1 1 2 2 3
1 1 1 2 2 3

Sample Output 1

Yes
2 2 3 1 1 1

Sample Input 2

3
1 1 2
1 1 3

Sample Output 2

No

Sample Input 3

4
1 1 2 3
1 2 3 3

Sample Output 3

Yes
3 3 1 2

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [usize; n], b: [usize; n]);
    let a: Vec<usize> = a;
    let b: Vec<usize> = b;
    let pbs: BTreeSet<_> = b
        .clone()
        .into_iter()
        .enumerate()
        .map(|(i, x)| (x, i))
        .collect();
    let mut ret = vec![];
    let mut ok = true;
    {
        for d in 1..10 {
            let mut b: VecDeque<_> = b.clone().into();
            for _ in 0..d {
                let c = b.pop_back().unwrap();
                b.push_front(c);
            }
            if (0..n).all(|i| a[i] != b[i]) {
                println!("{}", "Yes");
                println!("{}", b.into_iter().map(|x| x.to_string()).join(" "));
                return;
            }
        }
    }
    for d in 1..30 {
        ok = true;
        ret.clear();
        let mut bs = pbs.clone();
        for &ai in &a {
            let bi = if let Some(&bi) = bs.range(((ai + d, 0))..).next() {
                bi
            } else if let Some(&bi) = bs.iter().next() {
                if ai == bi.0 {
                    ok = false;
                    break;
                }
                bi
            } else if let Some(&bi) = bs.range(((ai + 1, 0))..).next() {
                bi
            } else {
                ok = false;
                break;
            };
            bs.remove(&bi);
            ret.push(bi.0);
        }
        if ok {
            break;
        }
    }
    if !ok {
        for d in 0..30 {
            ok = true;
            ret.clear();
            let mut bs = pbs.clone();
            for &ai in a.iter().rev() {
                let bi = if let Some(&bi) = bs
                    .range(..(if ai >= d { ai - d } else { 0 }, 0))
                    .rev()
                    .next()
                {
                    bi
                } else if let Some(&bi) = bs.iter().rev().next() {
                    if ai == bi.0 {
                        ok = false;
                        break;
                    }
                    bi
                } else if let Some(&bi) = bs.range(..(ai, 0)).rev().next() {
                    bi
                } else {
                    ok = false;
                    break;
                };
                bs.remove(&bi);
                ret.push(bi.0);
            }
        }
    }
    if ok {
        println!("{}", "Yes");
        println!(
            "{}",
            ret.into_iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
    } else {
        println!("{}", "No");
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}