#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int N, i;
  cin >> N;
  vector<int> A(N), X, Y;
  for (i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] != 0) {
      X.push_back(A[i]);
    }
  }
  for (i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] != 0) {
      Y.push_back(A[i]);
    }
  };
  int j = 0;
  bool ans = true;
  for (i = 0; i < N - 1; i++)
    if (Y[0] == X[i]) break;
  for (int x = 0; x < N - 1; ++i, ++j, ++x) {
    i %= N - 1;
    j %= N - 1;
    ;
    if (Y[j] != X[i]) {
      ans = false;
      break;
    }
  }
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
}
