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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
           
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
           
using namespace std;
using namespace __gnu_pbds;
           
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
           
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
           
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long;
           
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
}

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 100;
vector<int> qs[MAXN];
int t[MAXN * 4], pos[MAXN];

void update(int v, int tl, int tr, int pos, int val) {
    if (tl + 1 == tr) {
        t[v] = val;
        return;
    }
    int tm = (tl + tr) >> 1;
    if (pos < tm) {
        update(v * 2 + 1, tl, tm, pos, val);
    }
    else {
        update(v * 2 + 2, tm, tr, pos, val);
    }
    t[v] = min(t[v * 2 + 1], t[v * 2 + 2]);
}

int get(int v, int tl, int tr, int l, int r) {
    if (tl >= r || tr <= l) {
        return INF;
    }
    if (tl >= l && tr <= r) {
        return t[v];
    }
    int tm = (tl + tr) >> 1;
    int a = get(v * 2 + 1, tl, tm, l, r);
    int b = get(v * 2 + 2, tm, tr, l, r);
    return min(a, b);
}

signed main() {
    FAST_IO();
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vector<int> order(n);
    iota(all(order), 0);
    sort(all(order), [&](int f, int s) {
        return b[f] < b[s];
    });
    sort(all(b));
    vector<int> tmp(n);
    for (int i = 0; i < n; ++i) {
        tmp[i] = a[order[i]];
    }
    a = tmp;
    vector<int> sorted = a;
    sort(all(sorted));
    for (int i = 0; i < n; ++i) {
        if (sorted[i] > b[i]) {
            cout << "No\n";
            return 0;
        }
    }
    iota(all(order), 0);
    sort(all(order), [&](int f, int s) {
        return a[f] < a[s];
    });
    for (int i = n - 1; i >= 0; --i) {
        int pos = lower_bound(all(b), a[order[i]]) - b.begin();
        qs[pos].push_back(i);
    }
    for (int i = 0; i < n; ++i) {
        update(0, 0, n, i, order[i]);
        pos[order[i]] = i;
    }
    for (int l = 0; l < n; ++l) {
        for (int r : qs[l]) {
            if (get(0, 0, n, l, r + 1) <= r) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}