#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int n, x, ord1[MAXN], ord2[MAXN], first1, first2, i;
int main() {
  scanf("%d", &n);
  n--;
  i = 0;
  while (i < n) {
    scanf("%d", &x);
    if (x != 0) {
      ord1[i] = x;
      i++;
    }
  }
  first1 = 0;
  i = 0;
  while (i < n) {
    scanf("%d", &x);
    if (x != 0) {
      ord2[i] = x;
      if (x == ord1[0]) first2 = i;
      i++;
    }
  }
  while ((ord1[first1] == ord2[first2]) && (first1 < n)) {
    first1++;
    first2++;
    if (first2 == n) first2 = 0;
  }
  if (first1 == n)
    printf("YES");
  else
    printf("NO");
  return 0;
}
