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: Wrong Answer)

// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;
// use std::collections::BTreeSet;


// const INF: i64 = 1_000_000_000;
// const MOD: i64 = 998244353;


fn argsort(xs: &[i32]) -> Vec<usize> {
    let n = xs.len();
    let mut is: Vec<usize> = (0..n).into_iter().collect();
    is.sort_by_key(|&i| xs[i]);
    is
}

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());
    let n: usize = sc.read();
    let mut a: Vec<i32> = vec![];
    let mut b: Vec<i32> = vec![];
    for _ in 0..n {
        a.push(sc.read());
    }
    for _ in 0..n {
        b.push(sc.read());
    }
    let a = a;
    let b = b;
    let ia = argsort(&a);
    let ib = argsort(&b);
    // println!("{:?}", a);
    // println!("{:?}", ia);
    let mut perm = vec![!0; n];
    let mut good = true;
    for k in 0..n {
        good &= a[ia[k]] <= b[ib[k]];
        perm[ia[k]] = ib[k];
    }
    let mut uniq = true;
    for k in 0..n-1 {
        uniq &= a[ia[k+1]] > b[ib[k]]
    }
    let mut cyc = true;
    {
        let mut k = 0;
        for _ in 0..n-1 {
            k = perm[k];
            cyc &= k != 0;
        }
    }
    let ans = good && (uniq || !cyc);
    println!("{}", if ans { "Yes" } else { "No" });
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}