#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  vector<int> Ai(n - 1), Bi(n - 1);
  int t = 0;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    if (A[i] != 0) {
      Ai[t] = A[i];
      t++;
    }
  }
  t = 0;
  for (int i = 0; i < n; ++i) {
    cin >> B[i];
    if (B[i] != 0) {
      Bi[t] = B[i];
      t++;
    }
  }
  int i0 = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (Bi[i] == Ai[0]) {
      i0 = i;
      break;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    if (Bi[(i + i0) % (n - 1)] != Ai[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
