#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const long long LLINF = (long long)1e18;
const int LOG = 17;
const int N = (int)2e5 + 5;
const double PI = 3.141592653589793;
const double eps = 0.000005;
void operator delete(void* a) {}
void operator delete[](void* a) {}
int n;
vector<int> a, b;
int pos[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x > 0) {
      a.push_back(x);
    }
  }
  cout << '\n';
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x > 0) {
      b.push_back(x);
      pos[x] = b.size() - 1;
    }
  }
  int start = pos[a[0]];
  bool ok = true;
  for (int i = 0; i + 1 < n; ++i) {
    if (b[(start + i) % (n - 1)] != a[i]) {
      ok = false;
    }
  }
  if (ok)
    puts("YES");
  else
    puts("NO");
  return 0;
}
