#include <bits/stdc++.h>
using namespace std;
int a[10000 + 200000], b[200000 + 10000];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int i, j = 0;
    for (i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      if (x == 0) {
        continue;
      }
      a[j++] = x;
    }
    int pos;
    j = 0;
    for (i = 0; i < n; i++) {
      int x;
      scanf("%d", &x);
      if (x == 0) continue;
      b[j++] = x;
      if (x == a[0]) {
        pos = j - 1;
      }
    }
    bool f = false;
    for (i = 0; i < n - 1; i++) {
      if (a[i] != b[(i + pos) % (n - 1)]) f = true;
    }
    if (f) {
      printf("NO\n");
    } else
      printf("YES\n");
  }
  return 0;
}
