#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> as(n), bs(n);
  for (auto&& a : as) {
    cin >> a;
  }
  for (auto&& b : bs) {
    cin >> b;
  }
  as.erase(remove(as.begin(), as.end(), 0), as.end());
  bs.erase(remove(bs.begin(), bs.end(), 0), bs.end());
  for (int i = 0; i < as.size(); ++i) {
    bool valid = true;
    for (int j = 0; j < as.size(); ++j) {
      if (as[j] != bs[(j + i) % bs.size()]) {
        valid = false;
        break;
      }
    }
    if (valid) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
