#include <bits/stdc++.h>
unsigned A[444444];
int main() {
  unsigned n, i = -1, j;
  for (scanf("%u", &n); ++i < n; scanf("%u", A + i))
    ;
  for (i = -1; ++i < n;) A[i + n] = A[i];
  for (j = 0; !j; scanf("%u", &j)) --n;
  for (i = -1; A[++i] != j;)
    ;
  while (n--) {
    scanf("%u", &j);
    if (!j) continue;
    while (!A[++i])
      ;
    if (A[i] != j) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
