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: Accepted)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
int A[MAX_N];
int B[MAX_N];
int tA[MAX_N];
int tB[MAX_N];
pair<int,int> P[MAX_N];

bool solve() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = nextInt();
  {
    REP(i, N) tA[i] = A[i];
    REP(i, N) tB[i] = B[i];
    sort(tA, tA + N);
    sort(tB, tB + N);
    REP(i, N) if (tA[i] > tB[i]) return false;

    for (int i = 1; i < N; i++) {
      swap(tA[i-1], tA[i]);
      if (tA[i] <= tB[i] && tA[i-1] <= tB[i-1]) return true;
      swap(tA[i-1], tA[i]);
    }
  }

  REP(i, N) P[i] = make_pair(A[i], B[i]);
  sort(P, P+N, [](const pair<int,int>&a, const pair<int,int>& b){
    return a.second < b.second;
  });
  REP(i, N) P[i] = make_pair(P[i].first, i);
  sort(P, P+N);

  int cycle_len = 0;
  int i = 0;
  do {
    i = P[i].second;
    cycle_len++;
  } while (i != 0);
  if (cycle_len == N) return false;
  return true;
}

int main2() {
  bool ans = solve();
  cout << (ans?"Yes":"No") << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}