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::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;
#[allow(dead_code)]
const N_PRIME : i64 = 1000000007;

////////////////////////////////////////////////
/// 
// fn f(mut a:Vec<i64>,mut  b:Vec<i64>){
//     a.sort();
//     b.sort();
// 
//     for i in 0..a.len(){
//         if a[i] > b[i]{
//             println!("No");
//             std::process::exit(0);
//         }
//     }
// }

fn main(){
    let _ = read_int();
    let mut a = read_ints();
    let mut b = read_ints();
    let mut bad_a = vec![];
    let mut bad_b = vec![];
    let mut goods = vec![];

    for i in 0..a.len(){
        if a[i] > b[i]{
            bad_a.push(a[i]);
            bad_b.push(b[i]);
        }else if a[i] != b[i]{
            goods.push((a[i], b[i]));
        }
    }

    // goods.sort_by_key(|p| -p.0);
    // println!("{:?}",goods);

    for _ in 0..a.len() - 2{
        if bad_a.len() == 0{
            break;
        }

        let low = bad_a[0];
        let high = bad_b[0];
        bad_a.remove(0);
        bad_b.remove(0);

        let mut index = a.len();
        for i in 0..goods.len(){
            if goods[i].0 <= high && low <= goods[i].1{
                index = i;
                break;     
            }
        }
        if index == a.len(){
            println!("No");
            return;
        }

        let (aa, bb) = goods[index];
        if low != bb{ goods.push((low, bb)); }
        if aa != high { goods.push((aa, high));}
        goods.remove(index);
    }

    if bad_a.len() == 0{
        println!("Yes");
    }else{
        println!("No");
    }
}