#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
void arquivo() {
  freopen("", "r", stdin);
  freopen("", "w", stdout);
}
const int N = 200200;
int pi[500001], res[500001], nres;
void kmp(vector<long long> text, vector<long long> pattern) {
  nres = 0;
  pi[0] = -1;
  for (int i = 1; i < pattern.size(); ++i) {
    pi[i] = pi[i - 1];
    while (pi[i] >= 0 && pattern[pi[i] + 1] != pattern[i]) pi[i] = pi[pi[i]];
    if (pattern[pi[i] + 1] == pattern[i]) ++pi[i];
  }
  int k = -1;
  for (int i = 0; i < text.size(); ++i) {
    while (k >= 0 && pattern[k + 1] != text[i]) k = pi[k];
    if (pattern[k + 1] == text[i]) ++k;
    if (k + 1 == pattern.size()) {
      res[nres++] = i - k;
      k = pi[k];
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<long long> a, b;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == 0) continue;
    a.push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == 0) continue;
    b.push_back(x);
  }
  for (int i = 0; i < n - 1; ++i) {
    a.push_back(a[i]);
  }
  kmp(a, b);
  puts(nres ? "YES" : "NO");
  return 0;
}
