#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    deque<int> main(n - 1);
    deque<int> off(n - 1);
    int j = 0, data;
    for (size_t i = 0; i < n; i++) {
      cin >> data;
      if (data != 0) {
        main[j] = data;
        j++;
      }
    }
    j = 0;
    for (size_t i = 0; i < n; i++) {
      cin >> data;
      if (data != 0) {
        off[j] = data;
        j++;
      }
    }
    int counter = 0;
    bool no = true;
    while (counter <= n + 1) {
      off.push_front(off[n - 2]);
      off.pop_back();
      if (off == main) {
        cout << "YES" << endl;
        no = false;
        counter = n + 5;
      } else {
        counter++;
      }
    }
    if (no) {
      cout << "NO" << endl;
    }
  }
  return 0;
}
