#include <bits/stdc++.h>
using namespace std;
const int nx[8] = {2, -2, -2, 2, 1, 1, -1, -1};
const int ny[8] = {1, 1, -1, -1, 2, -2, -2, 2};
const long long LINF = (long long)2e18;
const int INF = 1e9 + 7;
const int N = 2e6 + 50;
const int MIN = 5e3 + 5;
const double EPS = 1e-9, PI = 2 * acos(0.0);
int n;
int a[N], b[N], c[N], z[N], C[N];
int main() {
  cin >> n;
  int l = 0;
  for (int i = 0; i < n; i++) {
    cin >> C[i];
    if (C[i]) {
      a[l++] = C[i];
    }
  }
  l = 0;
  for (int i = 0; i < n; i++) {
    cin >> C[i];
    if (C[i]) {
      b[l++] = C[i];
    }
  }
  n = l;
  for (int i = 0; i < n; i++) {
    c[i] = a[i];
  }
  c[n] = -1;
  for (int i = n + 1; i <= n + n; i++) c[i] = c[i + n] = b[i - n - 1];
  z[0] = 0;
  bool ok = 0;
  for (int i = 1, l = 0, r = 0; i <= n + n + n; i++) {
    if (i <= r) {
      z[i] = min(z[i - l], r - i + 1);
    }
    while (i + z[i] <= n + n + n && c[z[i]] == c[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
    ok |= (z[i] == n);
  }
  cout << (ok ? "YES" : "NO");
  return 0;
}
