#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0, _i = (n); i < _i; ++i) {
    int x;
    cin >> x;
    if (x) a.push_back(x);
  }
  for (int i = 0, _i = (n); i < _i; ++i) {
    int x;
    cin >> x;
    if (x) b.push_back(x);
  }
  rotate(a.begin(), min_element((a).begin(), (a).end()), a.end());
  rotate(b.begin(), min_element((b).begin(), (b).end()), b.end());
  if (equal((a).begin(), (a).end(), b.begin()))
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
