#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200500;
int n;
int a[2 * MAXN];
int b[MAXN];
int s[4 * MAXN];
int z[4 * MAXN];
void calc(int n) {
  int l = 0;
  int r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (s[i + z[i]] == s[z[i]] && i + z[i] < n) z[i]++;
    if (r < i + z[i] - 1) {
      l = i;
      r = i + z[i] - 1;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n - 1; ++i)
    if (a[i] == 0) swap(a[i], a[i + 1]);
  for (int i = 0; i < n - 1; ++i)
    if (b[i] == 0) swap(b[i], b[i + 1]);
  n--;
  for (int i = 0; i < n; ++i) s[i] = a[i];
  s[n] = -1;
  for (int i = 0; i < n; ++i) s[n + 1 + i] = s[2 * n + 1 + i] = b[i];
  calc(3 * n + 1);
  bool ok = false;
  for (int i = 0; i < 3 * n + 1; ++i) ok |= z[i] >= n;
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
