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