#include <bits/stdc++.h>
using namespace std;
int n;
int a[200100], b[200100];
bool check() {
  int i, j;
  for (i = 0; i < n; i++) {
    if (a[i] == 1) break;
  }
  for (j = 0; j < n; j++) {
    if (b[j] == 1) break;
  }
  for (int k = 0; k < n; i = (i + 1) % n, j = (j + 1) % n, k++) {
    if (a[i] == 0) i = (i + 1) % n;
    if (b[j] == 0) j = (j + 1) % n;
    if (a[i] != b[j]) return false;
  }
  return true;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    int i;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++) {
      scanf("%d", &b[i]);
    }
    if (check())
      printf("YES\n");
    else
      puts("NO");
  }
  return 0;
}
