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)

use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line.split_whitespace().map(String::from).collect();
        self.index = 0;
    }
}

fn check(a: &Vec<i32>, b: &Vec<i32>) -> bool {
    a.iter().zip(b.iter()).all(|(&a, &b)| a != b)
}

fn take_a_chance(a: &Vec<i32>, b: &mut Vec<i32>) {
    let mut l = 0;
    let mut r = b.len() - 1;

    while l <= r {
        while l <= r && a[l] != b[l] {
            l += 1;
        }
        while l <= r && a[r] != b[r] {
            r -= 1;
        }
        if l <= r {
            b.swap(l, r);
            l += 1;
            if r > 0 {
                r -= 1;
            }
        }
    }
}

fn solve(a: Vec<i32>, mut b: Vec<i32>) -> Option<Vec<i32>> {
    for _ in 0..2 {
        take_a_chance(&a, &mut b);
        if check(&a, &b) {
            return Some(b);
        }
        b.reverse();
    }
    None
}

fn main() {
    let mut reader = TokenReader::new();
    let _ = reader.next::<usize>();
    let a = reader.vector();
    let b = reader.vector();

    if let Some(b) = solve(a, b) {
        println!("Yes");
        b.into_iter().for_each(|num| print!("{} ", num));
        println!();
    } else {
        println!("No");
    }
}