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 Go (1.14.1) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	B := ReadInts(N)

	cnt := make(map[int]int)
	for i := 0; i < N; i++ {
		cnt[A[i]]++
		cnt[B[i]]++
	}
	for _, c := range cnt {
		if c > N {
			fmt.Println("No")
			return
		}
	}

	type Val struct {
		Num, Type int
	}
	c := make([]*Val, 2*N)
	for i := 0; i < N; i++ {
		c[i] = &Val{Num: A[i], Type: 0}
		c[N+i] = &Val{Num: B[i], Type: 1}
	}
	sort.Slice(c, func(i, j int) bool {
		return c[i].Num < c[j].Num
	})

	type Pair struct {
		X, Y *Val
	}
	pairs := make([]*Pair, N)
	for i := 0; i < N; i++ {
		pairs[i] = &Pair{
			X: c[i],
			Y: c[i+N],
		}
	}

	type0Indices := make([]int, 0)
	type1Indices := make([]int, 0)
	for i := 0; i < N; i++ {
		if pairs[i].X.Type != pairs[i].Y.Type {
			continue
		}
		if pairs[i].X.Type == 0 {
			type0Indices = append(type0Indices, i)
		} else {
			type1Indices = append(type1Indices, i)
		}
	}
	for i := 0; i < len(type0Indices); i++ {
		j := type0Indices[i]
		k := type1Indices[i]
		if pairs[j].X.Num == pairs[k].Y.Num {
			pairs[j].Y, pairs[k].X = pairs[k].X, pairs[j].Y
		} else {
			pairs[j].Y, pairs[k].Y = pairs[k].Y, pairs[j].Y
		}
	}

	for i := 0; i < N; i++ {
		if pairs[i].X.Type == 1 {
			pairs[i].X, pairs[i].Y = pairs[i].Y, pairs[i].X
		}
	}
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].X.Num < pairs[j].X.Num
	})
	fmt.Println("Yes")
	for i := 0; i < N; i++ {
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%d", pairs[i].Y.Num)
	}
	fmt.Println()

	// for i := 0; i < N; i++ {
	// 	if c[i].Type == 1 {
	// 		c[i], c[i+N] = c[i+N], c[i]
	// 	}
	// }
	// indices := make([]int, N) // indices of c
	// for i := 0; i < N; i++ {
	// 	indices[i] = i
	// }
	// sort.Slice(indices, func(i, j int) bool {
	// 	return c[indices[i]].Num < c[indices[j]].Num
	// })
	// fmt.Println("Yes")
	// for i := 0; i < N; i++ {
	// 	if i > 0 {
	// 		fmt.Printf(" ")
	// 	}
	// 	fmt.Printf("%d", c[indices[i]+N].Num)
	// }
	// fmt.Println()
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}