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)

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename Abelian>
struct BIT {
  BIT(int n, const Abelian &UNITY = 0) : n(n), UNITY(UNITY), dat(n, UNITY) {}

  void add(int idx, const Abelian &value) {
    while (idx < n) {
      dat[idx] += value;
      idx |= idx + 1;
    }
  }

  Abelian sum(int idx) {
    Abelian res = UNITY;
    while (idx >= 0) {
      res += dat[idx];
      idx = (idx & (idx + 1)) - 1;
    }
    return res;
  }

  Abelian sum(int left, int right) { return sum(right) - sum(left - 1); }

  Abelian operator[](const int idx) { return sum(idx, idx); }

  int lower_bound(Abelian value) {
    if (value <= UNITY) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      if (res + mask - 1 < n && dat[res + mask - 1] < value) {
        value -= dat[res + mask - 1];
        res += mask;
      }
    }
    return res;
  }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat;
};

template <typename T>
long long inversion_number(const vector<T> &a) {
  int n = a.size();
  vector<T> cp(a);
  sort(ALL(cp));
  cp.erase(unique(ALL(cp)), cp.end());
  BIT<int> bit(cp.size());
  long long res = 0;
  REP(i, n) {
    int idx = lower_bound(ALL(cp), a[i]) - cp.begin();
    res += i - bit.sum(idx);
    bit.add(idx, 1);
  }
  return res;
}

int main() {
  int n; cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  vector<int> cop_a(a), cop_b(b);
  sort(ALL(cop_a));
  sort(ALL(cop_b));
  REP(i, n) {
    if (cop_a[i] > cop_b[i]) {
      cout << "No\n";
      return 0;
    }
  }
  map<int, int> group;
  map<int, set<int> > elem;
  int l = 0;
  FOR(i, 1, n) {
    if (cop_a[i] > cop_b[l]) {
      int sz = group.size();
      FOR(j, l, i) {
        group[cop_a[j]] = sz;
        elem[sz].emplace(cop_b[j]);
      }
      l = i;
    }
  }
  int sz = group.size();
  FOR(j, l, n) {
    group[cop_a[j]] = sz;
    elem[sz].emplace(cop_b[j]);
  }
  REP(i, n) {
    if (elem[group[a[i]]].count(b[i]) == 1) {
      cout << "Yes\n";
      return 0;
    }
  }
  vector<pair<int, int> > ba(n);
  REP(i, n) ba[i] = {b[i], a[i]};
  sort(ALL(ba));
  vector<int> atara_a(n);
  REP(i, n) atara_a[i] = ba[i].second;
  cout << (inversion_number(atara_a) == n - 1 ? "No\n" : "Yes\n") << '\n';
  return 0;
}