#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x == 0) continue;
    a.push_back(x);
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x == 0) continue;
    b.push_back(x);
  }
  n = a.size();
  if (a.size() == b.size()) {
    int s = -1;
    {
      auto it = find(begin(b), end(b), a[0]);
      if (it != b.end()) {
        s = it - b.begin();
      }
    }
    if (s == -1) {
      cout << "NO" << endl;
      return 0;
    }
    rotate(b.begin(), b.begin() + s, b.end());
    cout << (a == b ? "YES" : "NO") << endl;
  } else {
    cout << "NO" << endl;
  }
}
