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

#define int long long

const long double PI = 3.14159265359;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (auto &val : a)
        cin >> val;
    for (auto &val : b)
        cin >> val;

    int l = -1, r = -1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] != b[i])
        {
            l = i;
            break;
        }
    }

    if (l == -1)
        return void(cout << "Yes" << '\n');

    for (int i = n - 1; i >= 0; i--)
    {
        if (a[i] != b[i])
        {
            r = i;
            break;
        }
    }

    vector<int> temp = a;
    // op1
    int val = temp[l];
    temp.erase(temp.begin() + l);
    temp.insert(temp.begin() + r, val);
    if (temp == b)
        return void(cout << "Yes" << '\n');
    // op2
    val = a[r];
    a.erase(a.begin() + r);
    a.insert(a.begin() + l, val);
    if (a == b)
        return void(cout << "Yes" << '\n');
    cout << "No" << '\n';
}

signed main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}