#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, a[210001], b[210001], p1, p2, w[210001], c[210001], d[210001];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]), p1 = (a[i]) ? p1 : i;
  for (i = 1; i <= n; i++) scanf("%d", &b[i]), p2 = (b[i]) ? p2 : i;
  for (i = 1, j = p1 + 1; i < n; i++, j++) {
    if (j > n) j = 1;
    c[i] = a[j];
    w[a[j]] = i;
  }
  for (i = 1, j = p2 + 1; i < n; i++, j++) {
    if (j > n) j = 1;
    d[i] = w[b[j]];
  }
  for (i = 1, j = 1; i < n - 1; i++) {
    if (d[i] == n - 1 && d[i + 1] == 1) continue;
    if (d[i] + 1 != d[i + 1]) {
      j = 0;
      break;
    }
  }
  puts(j ? "YES" : "NO");
  return 0;
}
