Problem:
Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

func swaps(n int, a, b []int) bool {
	// Sort the slice of B in ascending order.
	sort.Ints(b)

	// まず巡回置換 (p1, ..., pN ) を Ap1 ≦ Ap2 ≦ ... ≦ ApN となるようにとる
	ap := a
	sort.Ints(ap)

	// このとき Api ≦ Bi(i = 1, ..., N ) が成り立たなければ、1 つめの条件をみたす (p1 , ..., pN ) が存在しないので、false
	for i := 0; i < n; i++ {
		if ap[i] > b[i] {
			return false
		}

	}

	// Api ≦ Bi(i = 1,...,N) となる場合
	// 巡回置換(p1,...,pN)をサイクルに分解したときに、2つ以上のサイクルに分解されるならば、true
	// N-1回あればできるやつ
	// 目標位置をswapできる場所があれば、達成可能
	count := 0
	for i := 0; i < n-1; i++ {
		log.Print(b[i])
		if ap[i+1] <= b[i] {
			count++
		}
	}
	if count == n-1 {
		return true
	}

	// この時点で、Aは相異なり、目標インデックスも1つに決まる
	sort.Ints(a)
	count = 0
	x := 0
	for x != 0 {
		x = a[x]
		count++
	}

	if count != n {
		return true
	}
	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var n int
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}

	a := make([]int, n)
	if sc.Scan() {
		ss := strings.Split(sc.Text(), " ")
		for i := range ss {
			a[i], _ = strconv.Atoi(ss[i])
		}
	}

	b := make([]int, n)
	if sc.Scan() {
		ss := strings.Split(sc.Text(), " ")
		for i := range ss {
			b[i], _ = strconv.Atoi(ss[i])
		}
	}

	if swaps(n, a, b) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}