#include <bits/stdc++.h>
using namespace std;
int a[200001], b[200001], i, n, x, y;
int main() {
  scanf("%d\n", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
  scanf("\n");
  for (i = 1; i <= n; ++i) scanf("%d", &b[i]);
  scanf("\n");
  for (i = 1; i <= n; ++i) {
    if (a[i] == 1) x = i;
    if (b[i] == 1) y = i;
  }
  for (i = 1; i < n; ++i) {
    if (a[x] != b[y]) break;
    x = x % n + 1;
    y = y % n + 1;
    if (!a[x]) x = x % n + 1;
    if (!b[y]) y = y % n + 1;
  }
  if (i < n)
    printf("NO\n");
  else
    printf("YES\n");
}
