#include <bits/stdc++.h>
using namespace std;
int a[1000000 + 5], b[1000000 + 5];
int n, nex[1000000 + 5];
void getnext() {
  int k = 0;
  for (int i = 1; i < n; i++) {
    while (k != 0 && b[i] != b[k]) k = nex[k - 1];
    if (b[i] == b[k]) k++;
    nex[i] = k;
  }
}
bool kmp() {
  int k = 0;
  for (int i = 0; i < 2 * n; i++) {
    while (k != 0 && a[i] != b[k]) k = nex[k - 1];
    if (a[i] == b[k]) k++;
    if (k == n - 1) return true;
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0)
      i--;
    else
      a[i + n - 1] = a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 0) i--;
  }
  getnext();
  if (kmp())
    printf("YES");
  else
    printf("NO");
  return 0;
}
