#include <bits/stdc++.h>
int a[300000], b[300000];
int n, N;
int main() {
  while (scanf("%d", &n) != EOF) {
    int sum = 1;
    N = 0;
    bool sym = true;
    int ans1, ans2;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (a[i]) N++;
    }
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    for (int i = 0; i < n; i++)
      if (a[i]) {
        ans1 = i;
        break;
      }
    for (int i = 0; i < n; i++) {
      if (b[i] == a[ans1]) {
        ans2 = i + 1;
        break;
      }
    }
    for (int i = ans1 + 1;; i++) {
      if (sum == N) break;
      if (i == n) i = 0;
      if (a[i]) {
        if (ans2 == n) ans2 = 0;
        while (!b[ans2]) {
          ans2++;
          if (ans2 == n) ans2 = 0;
        }
        if (b[ans2] == a[i]) {
          sum++;
        } else {
          sym = false;
          break;
        }
        ans2++;
      }
    }
    if (sym)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
