#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, u = 0;
  cin >> n;
  vector<int> A, B;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x) A.push_back(x);
  }
  for (int i = 0; i < n - 1; i++) A.push_back(A[i]);
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x) B.push_back(x);
  }
  while (A[u] != B[0]) u++;
  for (int i = u; i < n + u - 1; i++)
    if (A[i] != B[i - u]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
