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 Kotlin (1.3.71) (judge verdict: Wrong Answer)

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = Array(n) { sc.nextInt() }
    val c = Array(n) { 0 }
    var l = 0
    var r = 0
    for (i in 0 until n) {
        while (l < n && a[l] < b[i]) l++
        if (l == n || a[l] != b[i]) continue
        r = l
        while (r + 1 < n && a[r + 1] == b[i]) r++
        if (a[n - 1] == b[i]) r = n - 1
        var d1 = l - i
        if (d1 < 0) d1 += n
        var d2 = r - i
        if (d2 < 0) d2 += n
        if (d1 <= d2) {
            c[d1]++
            if (d2 + 1 != n) {
                c[d2 + 1]--
            }
        } else {
            c[0]++
            c[d2 + 1]--
            c[d1]++
        }
    }
    val d = Array(n) { c[0] }
    for (i in 1 until n) {
        d[i] = d[i - 1] + c[i]
    }
    if (!d.contains(0)) {
        println("No")
    } else {
        val sh = (0 until n).first { d[it] == 0 }
        val ans = (0 until n).map { b[(it + sh) % n] }
        println("Yes")
        println(ans.joinToString(" "))
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}