#include <bits/stdc++.h>
using namespace std;
int n;
int numa[400005], numb[200005];
bool jg(int a, int kk) {
  int tmp1 = a;
  int tmp2 = kk;
  while (numa[tmp1] == numb[tmp2] && tmp1 <= 2 * n && tmp2 <= n) {
    tmp1++;
    tmp2++;
    if (!numa[tmp1]) tmp1++;
    if (!numb[tmp2]) tmp2++;
  }
  if (tmp2 > n) return true;
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &numa[i]);
  for (int i = 1 + n; i <= 2 * n; i++) numa[i] = numa[i - n];
  for (int i = 1; i <= n; i++) scanf("%d", &numb[i]);
  int kk;
  if (numb[1] == 0)
    kk = 2;
  else
    kk = 1;
  for (int i = 1; i <= n; i++) {
    if (numa[i] == numb[kk]) {
      if (jg(i, kk)) {
        printf("YES\n");
        return 0;
      }
    }
  }
  printf("NO\n");
  return 0;
}
