#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a;
  vector<long long> b;
  map<long long, long long> fn;
  a.clear();
  b.clear();
  long long x;
  for (long long(i) = 0; (i) < (n); ++(i)) {
    cin >> x;
    if (x) {
      fn[x] = a.size() + 1;
      a.push_back(x);
    }
  }
  for (long long(i) = 0; (i) < (n); ++(i)) {
    cin >> x;
    if (x != 0) {
      b.push_back(fn[x]);
    }
  }
  bool f = 1;
  for (long long(i) = 0; (i) < (n - 1); ++(i)) {
    if (b[(i + 1) % (n - 1)] != (b[i] == n - 1 ? 1 : b[i] + 1)) {
      f = 0;
      break;
    }
  }
  cout << (f ? "YES" : "NO");
  return 0;
}
