#include <bits/stdc++.h>
using namespace std;
const int maxn = 400005;
int a[maxn];
int b[maxn];
int n;
int ip[maxn];
vector<int> V;
int doit() {
  V.clear();
  for (int i = 1; i <= n; i++)
    if (a[i]) V.push_back(a[i]);
  memset(ip, 0, sizeof(ip));
  for (int i = 0; i < n - 1; i++) ip[V[i]] = V[(i + 1) % (n - 1)];
  V.clear();
  if (n == 2) return true;
  for (int i = 1; i <= n; i++)
    if (b[i]) V.push_back(b[i]);
  for (int i = 0; i < n - 1; i++) {
    if (ip[V[i]] == V[(i + 1) % (n - 1)]) continue;
    return false;
  }
  return true;
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    doit() ? puts("YES") : puts("NO");
  }
  return 0;
}
