#include <bits/stdc++.h>
using namespace std;
long long n, a[200005], b[200005], t, h;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (!a[i]) h = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (!b[i]) t = i - 1;
  }
  if (t == 0) t = n;
  long long y = 0;
  for (int i = h - 1; i >= 1; i--) {
    if (a[i] == b[t]) {
      h = i;
      y = 1;
      break;
    }
    swap(a[i], a[i + 1]);
  }
  if (!y) {
    if (a[n] != b[t]) {
      swap(a[n], a[1]);
      for (int i = n - 1; i >= 1; i--) {
        if (a[i] == b[t]) {
          h = i;
          break;
        }
        swap(a[i], a[i + 1]);
      }
    } else
      h = n;
  }
  long long j = t;
  for (int i = h; i <= n; i++) {
    if (b[j] != a[i]) {
      cout << "NO\n";
      return 0;
    }
    j++;
    if (j > n) j = 1;
  }
  for (int i = 1; i < h; i++) {
    if (b[j] != a[i]) {
      cout << "NO\n";
      return 0;
    }
    j++;
    if (j > n) j = 1;
  }
  cout << "YES\n";
  return 0;
}
