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 Scala (2.13.1) (judge verdict: Runtime Error)

object Main extends App {
  val sc = new java.util.Scanner(System.in);
  val n = sc.nextInt();
  val as = IndexedSeq.fill(n)(sc.nextInt);
  val bs = IndexedSeq.fill(n)(sc.nextInt);

  val asx = new Array[Int](n + 1);
  val bsx = new Array[Int](n + 1);
  {
    var asv: Int = 0;
    var bsv: Int = 0;
    (0 to n).foreach { i =>
      while (i == n && asv <= n || i < n && as(i) > asv) {
        asv = asv + 1;
        asx(asv - 1) = i;
      }
      while (i == n && bsv <= n || i < n && bs(i) > bsv) {
        bsv = bsv + 1;
        bsx(bsv - 1) = i;
      }
    }
  }

  val asc = (0 until n).map(i => asx(i + 1) - asx(i)).toArray;
  val bsc = (0 until n).map(i => bsx(i + 1) - bsx(i)).toArray;

  if ((0 until n).exists(i => asc(i) + bsc(i) > n)) {
    println("No");
  } else {
    println("Yes");
    val answer = Array.fill(n)(0);
    val asc_sorted = asc.zipWithIndex.sortBy(  _._2).sortBy(- _._1);
    val bsc_sorted = bsc.zipWithIndex.sortBy(- _._2).sortBy(- _._1);
    var iai: Int = 0;
    var iaj: Int = 0;
    var ib1i: Int = 0;
    var ib2i: Int = 0;
    var ib2j: Int = 0;
    while (iai < n) {
      if (bsc_sorted(ib2i)._2 == asc_sorted(iai)._2) {
        ib2i = ib2i + 1;
      } else if (iaj == asc_sorted(iai)._1) {
        iai = iai + 1;
        iaj = 0;
      } else if (ib2j == bsc_sorted(ib2i)._1) {
        bsc(bsc_sorted(ib2j)._1) = 0;
        if (bsc(bsc_sorted(ib1i)._2) > 0) {
          ib2i = ib1i;
        } else {
          ib2i = ib2i + 1;
        }
        ib2j = 0;
      } else {
        val idx = asx(asc_sorted(iai)._2);
        val value = bsc_sorted(ib2i)._2 + 1;
        println("DEBUG " + idx + " " + iaj);
        answer(idx + iaj) = value;
        iaj = iaj + 1;
        ib2j = ib2j + 1;
      }

    }
    
    println(answer.mkString(" "));
  }
}