#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long> v;
  long n;
  cin >> n;
  long a;
  for (long i = 0; i < n; ++i) {
    cin >> a;
    if (a != 0) v.push_back(a);
  }
  v.push_back(-1);
  for (long i = 0; i < n; ++i) {
    cin >> a;
    if (a != 0) v.push_back(a);
  }
  for (long i = n; i < 2 * n - 1; ++i) v.push_back(v[i]);
  long mx = -1, j;
  vector<long> pf;
  pf.resize(v.size(), 0);
  for (long i = 1; i < pf.size(); ++i) {
    j = pf[i - 1];
    while ((j != 0) && (v[i] != v[j])) {
      j = pf[j - 1];
    }
    if (v[i] == v[j]) ++j;
    pf[i] = j;
    mx = max(j, mx);
  }
  cout << (mx == (n - 1) ? "YES" : "NO") << endl;
  return 0;
}
