/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;
#define yes cout << "Yes\n", exit(0)
#define no cout << "No\n", exit(0)
#define YN(x) cout << ((x) ? "Yes\n" : "No\n"), exit(0)

int n, a[mxn], b[mxn];
map<int, int> ipa, ipb;

list<int> g[mxn];
bitset<mxn> vstd, inStack, ringOrig/*ring with more than one node*/;
int par[mxn], ring[mxn], cntRing;

void dfsRing(const int &u, const int &p) {
    vstd[u] = 1, inStack[u] = 1, par[u] = p;
    for (auto &v : g[u]) if (v != p) {
        if (!vstd[v]) dfsRing(v, u);
        else if (inStack[v]) {
            ringOrig[++cntRing] = 1;
            int x = u;
            while (ring[x] = cntRing, x != v) x = par[x];
        }
    }
    if (!ring[u]) ring[u] = ++cntRing;
    inStack[u] = 0;
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
// if even after sorting a to match order of b, it's not ok, answer is directly no.
// Let there is an edge between initial a[i] and sorted a[i], then we can swap in min n-number of cycles swaps.
// We can sort by number of cycles swaps, which is the best possible scenario. Even if we can't sort:
// Answer yes if we can do adjacent swaps in sorted a without harm,
// as then we don't need to care about those 2 and easily manage the others using n-2 swaps.

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ipa[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        ipb[b[i]] = i;
    }

    sort(a+1, a+n+1), sort(b+1, b+n+1);
    bool ok = 0;
    for (int i = 1; i <= n; i++) {
        // original position ipa[a[i]], sorted position ipb[b[i]]
        g[ipa[a[i]]].push_back(ipb[b[i]]);
        if (a[i] > b[i]) no;
        if (i>1) {
            swap(a[i], a[i-1]);
            ok |= (a[i-1] <= b[i-1] and a[i] <= b[i]);
            swap(a[i], a[i-1]);
        }
    }
    for (int i = 1; i <= n; i++) {
        if (!vstd[i]) dfsRing(i, 0);
    }
    ok |= cntRing > 1;
    YN(ok);
}

Measured memory_bytes: 20608