#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a, b;
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    if (num != 0) {
      a.push_back(num);
    }
  }
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    if (num != 0) {
      b.push_back(num);
    }
  }
  long long fi = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i] == a[0]) {
      fi = i;
      break;
    }
  }
  long long ans = 1;
  n = a.size();
  for (long long i = 0; i < n; i++) {
    long long x = a[i], y = b[((fi + i) % n)];
    if (x != y) {
      ans = 0;
      break;
    }
  }
  if (ans == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
