#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a0 = 0, b0 = 0;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) a0++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0) b0++;
  }
  if (a0 != b0) {
    cout << "NO" << endl;
    return 0;
  }
  vector<int> aq, bq;
  int ma = 0, mb = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) aq.push_back(a[i]);
    if (b[i] != 0) bq.push_back(b[i]);
  }
  for (int i = 0; i < aq.size(); i++) {
    if (aq[i] < aq[ma]) ma = i;
    if (bq[i] < bq[mb]) mb = i;
  }
  for (int i = 0; i < n; i++) {
    if (aq[(i + ma) % aq.size()] != bq[(i + mb) % bq.size()]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
