#include <bits/stdc++.h>
using namespace std;
int a[400000], b[400000], n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  int b1 = 0, a1;
  if (b[b1] == 0) b1++;
  for (int i = 0; i < n; i++)
    if (b[b1] == a[i]) {
      a1 = i;
      break;
    }
  for (int i = 0; i < n - 1; i++) {
    if (a[a1] == 0) a1++;
    if (b[b1] == 0) b1++;
    if (a[a1] != b[b1]) {
      printf("NO");
      return 0;
      break;
    }
    a1++;
    b1++;
  }
  printf("YES");
}
