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)

// https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

struct UnionFind {
      n: usize,
      parent: Vec<usize>,
      count: Vec<usize>
}

impl UnionFind {
     fn new(n: usize) -> Self {
           let mut p = vec![0; n];
           for i in 0..n {
                 p[i] = i;
           }
           UnionFind { n: n, parent: p, count: vec![1; n] }
     }

     fn find(&mut self, a: usize) -> usize {
           if self.parent[a] == a {
                 return a;
           }
           let par = self.parent[a];
           self.parent[a] = self.find(par);
           self.parent[a]
     }

     fn unite(&mut self, a: usize, b: usize) {
           let a = self.find(a);
           let b = self.find(b);
           if a == b {
                 return;
           }
           let ca = self.count[a];
           let cb = self.count[b];
           let total = ca + cb;
           self.count[b] = total;
           self.count[a] = total;
           if ca < cb {
                 self.parent[a] = b;
           } else {
                 self.parent[b] = a;
           }
     }

     fn same(&mut self, a: usize, b: usize) -> bool {
           self.find(a) == self.find(b)
     }

     fn count(&mut self, a: usize) -> usize {
           let a = self.find(a);
           self.count[a]
     }
}

fn solve(mut a: Vec<i32>, mut b: Vec<i32>) -> bool {
    let n = a.len();
    let mut ax = a.clone();
    ax.sort();
    let mut bs = b.clone();
    bs.sort();
    for i in 0..n {
        if ax[i] > bs[i] {
            return false;
        }
    }
    let mut ab = vec![];
    for i in 0..n {
        ab.push((a[i], b[i], i));
    }
    ab.sort_by_key(|x| x.0);
    for i in 0..n {
        ab[i].0 = bs[i];
        ab[i].2 = i;
    }
    ab.sort_by_key(|x| x.1);
    for i in 0..n {
        if ab[i].0 == ab[i].1 {
            // return true;
        }
    }
    for i in 0..n-1 {
        if ab[i].1 == ab[i+1].1 {
            return true;
        }
    }

    let mut uf = UnionFind::new(n);
    for i in 0..n {
        uf.unite(i, ab[i].2);
    }
    let mut ma = 0;
    for i in 0..n {
        ma = max(ma, uf.count(i));
    }
    return ma < n;
}

fn main() {
    input! {
        n: usize,
        a: [i32; n],
        b: [i32; n]
    };

    println!("{}", ifv!(solve(a, b), "Yes", "No"));
}