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