#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
bool chmin(T1 &a, T2 b) {
  return b < a && (a = b, true);
}
template <class T1, class T2>
bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < (n); i++) scanf("%d", &a[i]);
  for (int i = 0; i < (n); i++) scanf("%d", &b[i]);
  a.erase(find(a.begin(), a.end(), 0));
  b.erase(find(b.begin(), b.end(), 0));
  rotate(a.begin(), find(a.begin(), a.end(), 1), a.end());
  rotate(b.begin(), find(b.begin(), b.end(), 1), b.end());
  cout << (a == b ? "YES" : "NO") << endl;
  return 0;
}
