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 Python (3.4.3) (judge verdict: Wrong Answer)

#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    ll = []
    pb = []
    for i in range(n):
        ll.append([la[i], lb[i]])
    ll.sort()
    for i in range(n):
        pb.append([ll[i][1], i])
    pb.sort()
    pc = [0 for _ in range(n)]
    for i in range(n):
        pc[pb[i][1]] = i
    # print(pb)
    # print(pc)

    la.sort()
    lb.sort()
    for i in range(n):
        if la[i] > lb[i]:
            print("No")
            return

    cnt = 0
    # print(ll)
    for i in range(n):
        j = pc[i]
        while i != j:
            if ll[i][0] != ll[j][0] and ll[i][1] != ll[j][1]:
                cnt += 1
            ll[i][1], ll[j][1] = ll[j][1], ll[i][1]
            pc[i], pc[j] = pc[j], pc[i]
            # print(i, j, ll[i], ll[j])
            j = pc[i]
    # print(ll)
    if cnt <= n-2:
        print("Yes")
    else:
        if cnt == n-1:
            print("Yes")
        else:
            print("No")
    

    # print('Yes')


if __name__ == '__main__':
    main()