#include <bits/stdc++.h>
using namespace std;
string str, pat;
int pi[200005] = {0};
void compute_prefix() {
  int match = 0;
  for (int trav = 1; trav < pat.length(); trav++) {
    while (match > 0 && pat[trav] != pat[match]) match = pi[match - 1];
    if (pat[trav] == pat[match]) match++;
    pi[trav] = match;
  }
}
vector<int> kmp_match() {
  compute_prefix();
  vector<int> ret;
  int match = 0;
  for (int trav = 0; trav < str.length(); trav++) {
    while (match > 0 && str[trav] != pat[match]) match = pi[match - 1];
    if (str[trav] == pat[match]) {
      match++;
      if (match == pat.length()) {
        ret.push_back(trav - pat.length() + 1);
        match = pi[match];
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int let;
    cin >> let;
    char letter = let + '0';
    if (let == 0) {
      i--;
      n--;
    } else {
      str += letter;
    }
  }
  n++;
  for (int i = 0; i < n; i++) {
    int let;
    cin >> let;
    char letter = let + '0';
    if (let == 0) {
      i--;
      n--;
    } else {
      pat += letter;
    }
  }
  n++;
  str = str + str;
  compute_prefix();
  if (kmp_match().empty()) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
  cin.ignore(2);
  return 0;
}
