#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> k(n - 1, 0);
  vector<int> v(n - 1, 0);
  int ki = 0;
  int vi = 0;
  for (int i = 0; i < n - 1;) {
    int z = 0;
    cin >> z;
    if (z != 0) {
      k[i] = z;
      i++;
    }
    if (z == 1) {
      ki = i - 1;
    }
  }
  for (int i = 0; i < n - 1;) {
    int z = 0;
    cin >> z;
    if (z != 0) {
      v[i] = z;
      i++;
    }
    if (z == 1) {
      vi = i - 1;
    }
  }
  int hany = 0;
  while (k[ki] == v[vi] && hany < n - 1) {
    ki++;
    vi++;
    if (ki == n - 1) {
      ki = 0;
    }
    if (vi == n - 1) {
      vi = 0;
    }
    hany++;
  }
  if (hany == n - 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
