#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a, b;
int main() {
  cin >> n;
  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);
  }
  int pos;
  for (int i = 0; i < n - 1; i++)
    if (b[i] == a[0]) {
      pos = i;
      break;
    }
  int i = 1, j = (pos + 1) % (n - 1);
  bool f = true;
  while (i < n - 1) {
    if (a[i] != b[j]) f = false;
    i++;
    j = (j + 1) % (n - 1);
  }
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
