#include <bits/stdc++.h>
using namespace std;
const int N = 15;
const int K = 500;
const int INF = 1e9 + 7;
vector<int> z_function(vector<int> s) {
  int n = (int)s.size();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
vector<int> a;
vector<int> b;
int main() {
  int n;
  scanf(" %d", &n);
  a = vector<int>(n);
  b = vector<int>(n);
  for (int i = 0; i < n; i++) {
    scanf(" %d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  vector<int> c;
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) c.push_back(a[i]);
  }
  c.push_back(0);
  for (int i = 0; i < n; i++) {
    if (b[i] != 0) c.push_back(b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (b[i] != 0) c.push_back(b[i]);
  }
  vector<int> z = z_function(c);
  for (int i = 0; i < z.size(); i++) {
    if (z[i] == n - 1) {
      printf("YES");
      return 0;
    }
  }
  printf("NO");
  return 0;
}
