#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n), brr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) cin >> brr[i];
  vector<int> as, bs;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) {
      for (int j = 0; j < n; j++) {
        int id = (i + j) % n;
        if (arr[id]) {
          as.push_back(arr[id]);
        }
      }
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (brr[i] == 1) {
      for (int j = 0; j < n; j++) {
        int id = (i + j) % n;
        if (brr[id]) {
          bs.push_back(brr[id]);
        }
      }
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (as[i] != bs[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
