#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int first = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9';) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  for (; ch >= '0' && ch <= '9';) {
    first = first * 10 + ch - '0';
    ch = getchar();
  }
  return first * f;
}
int n;
int a[200010], b[200010];
int main() {
  n = read();
  int tot = 0;
  for (int i = 0; i <= n - 1 - tot; i++) {
    a[i] = read();
    if (!a[i]) i--, tot++;
  }
  tot = 0;
  for (int i = 0; i <= n - 1 - tot; i++) {
    b[i] = read();
    if (!b[i]) i--, tot++;
  }
  n -= tot;
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= n - 1; j++)
      if (a[i] == b[j]) {
        for (int k = 0; k <= n - 1; k++)
          if (a[(i + k) % n] != b[(j + k) % n]) {
            printf("NO\n");
            return 0;
          }
        printf("YES\n");
        return 0;
      }
}
