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