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: Time Limit Exceeded)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use proconio::input;

use itertools::Itertools;
use ralgo::flow::dinic::Dinic;
use std::collections::VecDeque;

fn main() {
    input! {
        n: usize,
        mut a: [i32; n],
        mut b: [i32; n],
    };
    a.iter_mut().for_each(|x| *x *= 2);
    b.iter_mut().for_each(|x| *x *= 2);
    let mut g = Dinic::new();

    let ss: Vec<_> = (0..).take(n).collect();
    let tt: Vec<_> = (ss.last().unwrap() + 1..).take(n).collect();
    let inc: Vec<_> = (tt.last().unwrap() + 1..).take(n + 1).collect();
    let dec: Vec<_> = (inc.last().unwrap() + 1..).take(n + 1).collect();
    let s = dec.last().unwrap() + 1;
    let t = s + 1;

    let mut to_inc_edges = Vec::new();
    let mut from_inc_edges = Vec::new();
    for i in 0..n {
        g.add_edge(s, ss[i], 1);
        g.add_edge(tt[i], t, 1);
    }
    for i in 0..n {
        g.add_edge(inc[i], inc[i + 1], n as i32);
        from_inc_edges.push(g.add_edge(inc[i], tt[i], 1 as i32));

        g.add_edge(dec[i + 1], dec[i], n as i32);
        g.add_edge(dec[i + 1], tt[i], 1 as i32);
    }
    for (i, ai) in a.iter().enumerate() {
        let j = b.binary_search(&(ai - 1)).unwrap_or_else(|x| x);
        g.add_edge(ss[i], dec[j], 1);
        let j = b.binary_search(&(ai + 1)).unwrap_or_else(|x| x);
        to_inc_edges.push(g.add_edge(ss[i], inc[j], 1));
    }
    let mf = g.max_flow(s, t).0;
    if (mf as usize) == n {
        println!("Yes");
        let mut q = VecDeque::new();
        for i in 0..n {
            if g.get_flow(&to_inc_edges[i]) > 0 {
                q.push_back(i);
            }
        }
        let mut res = vec![0; n];
        let mut used = vec![false; n];
        for j in (0..n).filter(|&j| g.get_flow(&from_inc_edges[j]) == 1) {
            if let Some(&i) = q.front() {
                if b[j] > a[i] {
                    used[j] = true;
                    res[i] = b[j];
                    q.pop_front();
                }
            }
        }
        q.clear();
        for i in (0..n).rev() {
            if g.get_flow(&to_inc_edges[i]) == 0 {
                q.push_back(i);
            }
        }
        for j in (0..n).rev().filter(|&j| !used[j]) {
            if let Some(&i) = q.front() {
                if b[j] < a[i] {
                    res[i] = b[j];
                    q.pop_front();
                }
            }
        }
        println!("{}", res.iter().map(|x| x / 2).join(" "));
    } else {
        println!("No");
    }
}
*/

fn main() {
    let exe = "/tmp/bin7BB39C3B";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";