#include <bits/stdc++.h>
using namespace std;
string tout[6] = {"NO", "YES", "No", "Yes", "no", "yes"};
using vi = vector<int>;
using vll = vector<long long>;
using vld = vector<long double>;
using vch = vector<char>;
using mi = map<int, int>;
using mll = map<long long, long long>;
using msll = map<string, long long>;
using mlls = map<long long, string>;
using mchll = map<char, long long>;
using mstst = map<string, string>;
using si = set<int>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using pdd = pair<double, double>;
using sch = set<char>;
const long long INF = 1e9 + 5;
const long long MOD = 1e5 + 5;
const long long ARIGATO = 2e5 + 5;
const long long ASO = 1e18 + 5;
const long long ANI = 1e6 + 5;
const long long inf = -1e9;
const long long mod = -1e5;
const long long aso = -1e18;
const long long ISM = 1e4 + 5;
long long n, us[200000], dp[200000], ans, j, ans1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> us[i];
  }
  for (int j = 0; j < n; ++j) {
    cin >> dp[j];
  }
  j = 0;
  ans = 0;
  for (int i = 0; i < n; ++i) {
    ans1 = 0;
    if (!us[i]) continue;
    while (ans < n) {
      if (dp[j] == us[i]) {
        j++;
        j %= n;
        ans++;
        ans1 = 1;
        break;
      }
      j++;
      j %= n;
      ans++;
    }
    if (!ans1) {
      cout << tout[(0)] << "\n";
      return 0;
    }
    if (i == 0 || (us[0] == 0 && i == 1)) ans = 1;
  }
  cout << tout[(1)] << "\n";
  return 0;
}
