#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  vector<int> vet, mat;
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) vet.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) mat.push_back(x);
  }
  int aux = 0;
  if (n <= 3) {
    cout << "YES";
  } else {
    int r;
    for (int i = 0; i < n - 1; i++) {
      if (mat[i] == vet[0]) {
        r = i;
        break;
      }
    }
    for (int i = 0; i < n - 1; i++) {
      int l = r + i;
      if (l >= n - 1) l -= (n - 1);
      if (vet[i] != mat[l]) {
        aux = 1;
        break;
      }
    }
    if (aux) {
      cout << "NO";
    } else
      cout << "YES";
  }
  return 0;
}
