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