#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> w(n);
  for (int __i = 0; __i < (n); ++__i) cin >> v[__i];
  ;
  for (int __i = 0; __i < (n); ++__i) cin >> w[__i];
  ;
  v.erase(find(v.begin(), v.end(), 0));
  w.erase(find(w.begin(), w.end(), 0));
  int pos = find(w.begin(), w.end(), v[0]) - w.begin();
  vector<int> w2;
  for (int i = (pos); i < (w.size()); ++i) {
    w2.push_back(w[i]);
  }
  for (int i = (0); i < (pos); ++i) {
    w2.push_back(w[i]);
  }
  cout << (v == w2 ? "YES" : "NO");
}
