#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int b[200005];
int c[200005];
int d[200005];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) scanf("%d", b + i);
  int aux = 0;
  if (a[aux] == 0) aux++;
  for (int i = 0; i < n; i++) {
    if (b[i] == a[aux]) {
      int cnt = 0;
      for (int j = i; cnt < n; j++) {
        if (j == n) j = 0;
        c[cnt++] = b[j];
      }
      int j = 0;
      i = 0;
      while (true) {
        if (a[i] == 0 and i < n) i++;
        if (c[j] == 0 and j < n) j++;
        if (a[i] and c[j]) {
          if (a[i] != c[j]) {
            printf("NO\n");
            return 0;
          }
          if (i < n) i++;
          if (j < n) j++;
        }
        if (i == n and j == n) break;
      }
      printf("YES\n");
      return 0;
    }
  }
  return 0;
}
