#include <bits/stdc++.h>
using namespace std;
long long r, c, n, k, x, y, a[200005], b[200005], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i - k];
    if (a[i - k] == 0) k++;
  }
  k = -1;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0) continue;
    if (k == -1) {
      for (int j = 0; j < n - 1; j++) {
        if (b[i] == a[j]) {
          k = j + 1;
          k %= n - 1;
        }
      }
      continue;
    }
    if (a[k] != b[i]) {
      cout << "NO" << endl;
      return 0;
    }
    k++;
    k %= n - 1;
  }
  cout << "YES" << endl;
  return 0;
}
