#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 3;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 3;
long long mat[15][15];
long long cnt(long long s, long long e, long long k, long long l,
              long long kk) {
  long long xx = 0;
  for (long long i = s; i <= k; i++) {
    for (long long j = e; j <= l; j++) {
      xx += mat[i][j];
    }
  }
  return xx >= kk ? 1ll : 0ll;
}
void testcase() {
  long long n;
  cin >> n;
  long long *a = new long long[n];
  long long *b = new long long[n];
  vector<long long> u, v;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]) {
      v.push_back(a[i]);
    }
  }
  long long in;
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i]) {
      u.push_back(b[i]);
      if (u.back() == v[0]) {
        in = u.size() - 1;
      }
    }
  }
  bool ok = true;
  for (long long i = 0; i < v.size(); i++) {
    if (v[i] != u[in]) {
      ok = false;
    }
    in = (in + 1) % v.size();
  }
  cout << (ok ? "YES\n" : "NO\n");
  return;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    testcase();
  }
  return 0;
}
