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)

#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn impossible(mut a: Vec<isize>, mut b: Vec<isize>) -> bool {
    a.sort();
    b.sort();

    let n = a.len();
    for i in 0..n {
        if a[i] > b[i] {
            return true;
        }
    }
    false
}

fn solve1(a: Vec<isize>, b: Vec<isize>) -> bool {
    let n = a.len();
    let mut p: Vec<(isize, isize)> = Vec::new();
    for i in 0..n {
        p.push((a[i], b[i]));
    }
    p.sort_by_key(|&(x, y)| if x <= y { y - x } else { 1000000000 + (x - y) });
    for i in 0..10 {
        if i >= p.len() {
            continue;
        }
        let (x, y) = p[i];
        if x > y {
            continue;
        }
        let mut a = Vec::new();
        let mut b = Vec::new();
        for j in 0..n {
            if i != j {
                a.push(p[j].0);
                b.push(p[j].1);
            }
        }
        a.sort();
        b.sort();
        let mut this_is_ok = true;
        for j in 0..n - 1 {
            if a[j] > b[j] {
                this_is_ok = false;
            }
        }
        if this_is_ok {
            return true;
        }
    }
    false
}
fn solve2(a: Vec<isize>, b: Vec<isize>) -> bool {
    let n = a.len();
    let mut p: Vec<(isize, isize)> = Vec::new();
    for i in 0..n {
        p.push((a[i], b[i]));
    }
    p.sort_by_key(|&(x, y)| x - y);
    let (x1, y1) = p[0];
    let (x2, y2) = p[n - 1];
    if x1 <= y2 && x2 <= y1 {
        let mut a = Vec::new();
        let mut b = Vec::new();
        for j in 0..n {
            if j != 0 && j != n - 1 {
                a.push(p[j].0);
                b.push(p[j].1);
            }
        }
        a.sort();
        b.sort();
        let mut this_is_ok = true;
        for j in 0..n - 2 {
            if a[j] > b[j] {
                this_is_ok = false;
            }
        }
        if this_is_ok {
            return true;
        }
    }
    false
}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n: usize = sc.read();
    let a: Vec<isize> = sc.read_vec(n);
    let b: Vec<isize> = sc.read_vec(n);

    if impossible(a.clone(), b.clone()) {
        println!("No");
        return;
    }

    let mut ans = solve1(a.clone(), b.clone()) || solve2(a.clone(), b.clone());

    let mut p: Vec<(isize, isize)> = Vec::new();
    for i in 0..n {
        p.push((a[i], b[i]));
    }
    p.sort_by_key(|&(x, y)| x - y);

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

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

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}