#include <bits/stdc++.h>
int main() {
  int n, a[200000], b[200000];
  scanf("%i", &n);
  n--;
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%i", &c);
    if (c == 0)
      i--;
    else
      a[i] = c;
  }
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%i", &c);
    if (c == 0)
      i--;
    else
      b[i] = c;
  }
  int i = 0;
  while (i < n && a[i] != b[0]) i++;
  if (i == n) {
    printf("NO");
    return 0;
  }
  for (int j = 0; j < n; j++) {
    if (a[(i + j) % n] != b[j]) {
      printf("NO");
      return 0;
    }
  }
  printf("YES");
}
