#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

int n;
pair<int, int> ab[500000];
int sorted[3][500000];
int ok[3][500000];
int pref[3][500000];
map<int, int> pos;
int marked[500000];

void check()
{
	for (int i = 0; i < n; i++) if (sorted[1][i] > ab[i].se) {cout << "No"; exit(0);}
	cout << "Yes";
	exit(0);
}

bool comp(pii a, pii b)
{
    return a.se < b.se;
}

int get(int s, int l, int r)
{
    if (r < l) return 0;
    if (l == 0) return pref[s][r];
    return pref[s][r] - pref[s][l - 1];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> ab[i].fi;
    for (int i = 0; i < n; i++) cin >> ab[i].se;
    sort(ab, ab + n, comp);
    for (int i = 0; i < n; i++) sorted[1][i] = ab[i].fi;
    sort(sorted[1], sorted[1] + n);
    for (int i = 0; i + 1 < n; i++) if (sorted[1][i] == sorted[1][i + 1]) check();
    for (int i = 0; i < n; i++) pos[sorted[1][i]] = i;
    for (int i = 0; i < n; i++) if (marked[i] == 0)
    {
    	int j = pos[ab[i].fi];
    	while (j != i) marked[j] = 1, j = pos[ab[j].fi];
    	marked[n]++;
    }
    if (marked[n] > 1) check();
    for (int i = 0; i < n - 1; i++) sorted[0][i] = sorted[1][i + 1];
    for (int i = 1; i < n; i++) sorted[2][i] = sorted[1][i - 1];
    for (int i = 0; i < n - 1; i++) ok[0][i] = sorted[0][i] <= ab[i].se;
    for (int i = 0; i < n; i++) ok[1][i] = sorted[1][i] <= ab[i].se;
    for (int i = 1; i < n; i++) ok[2][i] = sorted[2][i] <= ab[i].se;
    for (int j = 0; j < 3; j++) for (int i = 0; i < n; i++) pref[j][i] = ok[j][i] + (i > 0 ? pref[j][i - 1] : 0);
    for (int i = 0; i < n; i++)
    {
        if (ab[i].fi > ab[i].se) continue;
        int j = pos[ab[i].fi];
        //cout << i << "\n";
        if (j < i)
        {
            int simb = 1 + get(1, 0, j - 1) + get(0, j, i - 1) + get(1, i + 1, n - 1);
            //cout << get(1, 0, j - 1) << " " << get(0, j, i - 1) << " " << get(1, i + 1, n - 1) << endl;
            if (simb == n)
            {
                cout << "Yes\n";
                return 0;
            }
        }
        if (j == i)
        {
            int simb = 1 + get(1, 0, i - 1) + get(1, i + 1, n - 1);
            if (simb == n)
            {
                cout << "Yes\n";
                return 0;
            }
        }
        if (j > i)
        {
            int simb = 1 + get(1, 0, i - 1) + get(2, i + 1, j) + get(1, j + 1, n - 1);
            if (simb == n)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
}



Measured memory_bytes: 23808