#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, p, q, flag = 0;
  int a[200000], b[200000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  p = q = 0;
  if (a[0] == 0) p++;
  while (b[q] != a[p]) q++;
  while (p < n) {
    if (a[p] != b[q]) {
      flag = 1;
      break;
    }
    p++;
    if (a[p] == 0) p++;
    q = (q + 1) % n;
    if (b[q] == 0) q = (q + 1) % n;
  }
  if (flag == 0)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
