#include <bits/stdc++.h>
using namespace std;
istream* pin;
uintmax_t konstansmod = (1e9) + 7;
template <typename T>
vector<T> read(int num = -1, int szorzo = 1, istream& in = *pin) {
  vector<T> container;
  if (num == -1) in >> num;
  num *= szorzo;
  for (int i = 0; i < num; i++) {
    T q;
    in >> q;
    container.push_back(q);
  }
  return container;
}
struct printer {
  ostream* o;
  printer(ostream& a = cout) : o(&a) {}
  void pr() { *o << "\n"; }
  template <typename T>
  void pr(T uintmax_t) {
    *o << std::setprecision(9) << uintmax_t << "\n";
  }
  template <typename T>
  void pr(vector<T> uintmax_t) {
    for (T w : uintmax_t) pr(w);
    pr();
  }
  template <typename T, typename... Args>
  void pr(T value, Args... args) {
    pr(value);
    pr(args...);
  }
};
template <typename H1>
void show(std::ostream& out, const char* label, H1&& value) {
  out << label << "=";
  printer(out).pr(value);
}
template <typename H1, typename... T>
void show(std::ostream& out, const char* label, H1&& value, T&&... rest) {
  const char* pcomma = strchr(label, ',');
  out.write(label, pcomma - label) << "=";
  printer(out).pr(value);
  show(out, pcomma + 1, std::forward<T>(rest)...);
}
void print(bool b) { cout << (b ? "Yes" : "No") << "\n"; }
void solve();
int main(int argc, char** argv) {
  srand((unsigned)time(NULL));
  ifstream* argfile = NULL;
  string filename = "";
  if (argc >= 2 && filename.length() == 0) filename = argv[1];
  if (filename.length() > 0) {
    argfile = new ifstream(filename);
    if (!argfile->is_open()) {
      cerr << "file cant be opened,exiting. Filename:" << filename << "\n";
      cerr << "Error: " << strerror(errno) << "\n";
      return 1;
    }
  }
  if (argfile) std::cin.rdbuf(argfile->rdbuf());
  istream& myfile = argfile ? *argfile : cin;
  pin = &myfile;
  int num;
  solve();
  return 0;
  myfile >> num;
  for (int i = 0; i < num; i++) {
    cout << "Case #" << (i + 1) << ": ";
    solve();
  }
  return 0;
}
void solve() {
  uintmax_t n;
  cin >> n;
  vector<uintmax_t> a, b;
  int ap, bp;
  for (int i = 0; i < n; i++) {
    uintmax_t q;
    cin >> q;
    a.push_back(q);
    if (q == 1) ap = i;
  }
  for (int i = 0; i < n; i++) {
    uintmax_t q;
    cin >> q;
    b.push_back(q);
    if (q == 1) bp = i;
  }
  for (int i = 0; i < n; i++) {
    if (a[ap] != b[bp]) {
      printf("NO\n");
      {};
      return;
    }
    ap = (ap + 1) % n;
    bp = (bp + 1) % n;
    if (a[ap] == 0) ap = (ap + 1) % n;
    if (b[bp] == 0) bp = (bp + 1) % n;
  }
  printf("YES\n");
}
