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