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 Rust (1.15.1) (judge verdict: Accepted)

pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let mut avec: Vec<u32> = read_vec();
    let mut bvec: Vec<u32> = read_vec();
    let mut ab: Vec<Vec<u32>> = vec![];
    for i in 0..n {
        ab.push(vec![avec[i], bvec[i]]);
    }
    ab.sort_by(|a, b| a[0].partial_cmp(&b[0]).unwrap());
    avec.sort();
    bvec.sort();

    if avec[0] > bvec[0] {
        println!("No");
        return;
    }
    let mut b = false;
    for i in 1..n {
        if avec[i] > bvec[i] {
            println!("No");
            return;
        }
        if avec[i] <= bvec[i - 1] {
            b = true;
        }
    }
    if b {
        println!("Yes");
        return;
    }

    //println!("{:?}", avec);
    //println!("{:?}", bvec);
    //println!("{:?}", ab);
    let mut tmp: Vec<(u32, usize)> = vec![];
    for i in 0..n {
        tmp.push((ab[i][1], i));
    }
    //println!("{:?}", tmp);
    tmp.sort_by(|x, y| x.0.partial_cmp(&y.0).unwrap());
    //println!("{:?}", tmp);

    let mut id: usize = 0;
    for _ in 0..n - 1 {
        id = tmp[id].1;
        if id == 0 {
            println!("Yes");
            return;
        }
    }
    if tmp[id].1 != 0 {
        loop {}
    }
    println!("No");
}