#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using Int = long long;
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<Int, Int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
Int get_msb(long long x) {
    assert(x != 0);
    return 63 - __builtin_clzll(x);
}
Int get_lsb(long long x) {
    assert(x != 0);
    return __builtin_ctzll(x);
}
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T> ostream& operator<<(ostream& s, const set<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T> ostream& operator<<(ostream& s, const multiset<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, const unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct FastIO { FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } fast_io;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr Int MOD = 1000000007;
// **********************************************************************************************
// **********************************************************************************************
// **********************************************************************************************
// **************************************** TEMPLATE END ****************************************
// **********************************************************************************************
// **********************************************************************************************
// **********************************************************************************************

template <class T, class F>
struct SegmentTree {
    const F op;
    const T e;
    SegmentTree(F op_, T e_) : op(op_), e(e_) {}
    int n;
    vector<T> t;
    void set_by_unit(int n_) {
        t.clear();
        n = n_;
        t.resize(2 * n, e);
    }
    void set_by_vector(const vector<T>& a) {
        t.clear();
        n = a.size();
        t.resize(2 * n, e);
        for (int i = 0; i < n; i++) t[i + n] = a[i];
        build();
    }
    void build() {
        for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
    T& operator[](int i) { return t[i + n]; }
    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= n);
        T resl = e, resr = e;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, t[l++]);
            if (r & 1) resr = op(t[--r], resr);
        }
        return op(resl, resr);
    }
    // iをaに変更
    void update(int i, const T& a) {
        assert(0 <= i && i < n);
        t[i += n] = a;
        while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
    }
};
template <class T, class F>
auto make_segment_tree(F op, T e) {
    return SegmentTree<T, F>(op, e);
}
// example
//    auto seg_mi = make_segment_tree<Int>([](Int a, Int b) { return min(a, b); }, 1e18);
//    auto seg_ma = make_segment_tree<Int>([](Int a, Int b) { return max(a, b); }, -1e18);

struct UnionFind {
    int cnt;                   // 集合の数
    vector<int> number;        // 0以上のとき親のindex, 負のときは集合サイズ
    vector<int> data1, data2;  // 連結成分ごとのデータ
    UnionFind(int n) : cnt(n), number(n, -1) {}
    UnionFind(const vector<int>& data1, const vector<int>& data2)
        : cnt(data1.size()), number(data1.size(), -1), data1(data1), data2(data2) {}
    int root(int x) { return number[x] < 0 ? x : number[x] = root(number[x]); }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (number[y] < number[x]) swap(x, y);
        // yをxにマージ
        number[x] += number[y];
        number[y] = x;
        // // dataのマージ方法に合わせて変える
        // data1[x] += data1[y];
        // data2[x] += data2[y];
        cnt--;
    }
    bool is_same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -number[root(x)]; }
    int& ref1(int x) { return data1[root(x)]; }
    int& ref2(int x) { return data2[root(x)]; }
};

void no() { 
    cout << "No" << endl;
    exit(0);
}
signed main() {
    Int n; cin >> n;
    vector<Int> p(n), q(n);
    REP (i, n) cin >> p[i];
    REP (i, n) cin >> q[i];
    vector<ii> a(n), b(n);
    REP (i, n) a[i] = {p[i], i}, b[i] = {q[i], i};
    sort(ALL(a));
    sort(ALL(b));
    vector<Int> rev_a(n), rev_b(n);
    REP (i, n) {
        rev_a[a[i].se] = i;
        rev_b[b[i].se] = i;
    }
    dump(rev_a, rev_b);
    REP (i, n) {
        if (b[i].fi < a[i].fi) no();
    }
    auto seg = make_segment_tree<Int>([](Int a, Int b) { return a && b; }, 1);
    seg.set_by_vector(vector<Int>(n));
    REPI (i, 1, n) {
        if (a[i].fi <= b[i - 1].fi) seg.update(i, 1);
    }
    REP (i, n) {
        if (p[i] > q[i]) continue;
        Int x = rev_a[i], y = rev_b[i];
        bool ok = true;
        if (x < y) {
            if (!seg.query(x + 1, y + 1)) ok = false;
        }
        dump(i, x, y, ok);
        if (ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    UnionFind uf(n);
    REP (i, n) {
        uf.unite(a[i].se, b[i].se);
    }
    if (uf.cnt == 1) no();

    cout << "Yes" << endl;
}


Measured memory_bytes: 8832