#include <bits/stdc++.h>
using namespace std;
int a[400001], x, b[200001], n, na, i, k;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x > 0) {
      na++;
      a[na] = x;
      a[n - 1 + na] = x;
    }
  }
  na = 0;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x > 0) {
      na++;
      b[na] = x;
    }
  }
  for (i = 1; i <= n; i++) {
    if (b[1] == a[i]) {
      na = i;
      break;
    }
  }
  for (i = 1; i < n; i++) {
    if (b[i] != a[na + i - 1]) {
      k = 1;
      break;
    }
  }
  if (k == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
