#include <bits/stdc++.h>
using namespace std;
int n, t1, p;
int b[200000], h[200000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (!b[i]) {
      --i;
      --n;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    if (h[i] == b[0]) p = i;
    if (!h[i]) --i;
  }
  for (int i = 0; i < n; i++) {
    if (b[i] != h[(p + i) % (n)]) {
      cout << "NO" << endl;
      exit(0);
    }
  }
  cout << "YES" << endl;
}
