#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
const long long lim = 6e5 + 5;
template <typename T1>
void printIt(T1 t1) {
  cout << t1 << " )" << endl;
}
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) {
  cout << t1 << " , ";
  printIt(t2...);
}
long long powP(long long x, long long y) {
  long long ans = 1, po = x % mod;
  while (y > 0) {
    if (y & 1) ans = ans * po % mod;
    y >>= 1;
    po = po * po % mod;
  }
  return ans;
}
long long findGcd(long long a, long long b) {
  while (a != 0) {
    long long temp = b % a;
    b = a;
    a = temp;
  }
  return b;
}
long long Array[lim], BArray[lim], CArray[lim];
vector<long long> V, W;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T, i, p, j, l, e, r, b, c, k, m, q, a, d, w, x, y, u, v, z, t, curr,
      prev, sum = 0, val, temp, countA = 0, indicator = 0, pos, h, minA, maxA,
            maxB, type, n, ans = 0, left, right;
  string A, B, C;
  A = "YES", B = "NO", C = "";
  T = 1;
  for (long long int tt = (1); tt <= (T); ++tt) {
    cin >> n;
    for (long long int i = (1); i <= (n); ++i) {
      cin >> x;
      if (x > 0) V.push_back(x);
    }
    for (long long int i = (1); i <= (n); ++i) {
      cin >> x;
      if (x > 0) W.push_back(x);
      Array[x] = W.size() - 1;
    }
    indicator = 0;
    curr = Array[V[0]];
    for (long long int i = (1); i <= (V.size() - 1); ++i) {
      if (Array[V[i]] != (curr + 1) % (n - 1)) indicator = 1;
      curr = (curr + 1) % (n - 1);
    }
    if (indicator == 0)
      cout << A << endl;
    else
      cout << B << endl;
  }
  return 0;
}
