#include <bits/stdc++.h>
const int M = 1001000;
const double esp = 1e-8;
const double PI = 3.141;
const int INF = 0x3f3f3f3f;
using namespace std;
int a[200100], b[200100];
int f(int num, int n) {
  for (int i = 0; i < n - 1; i++)
    if (a[i] == num) return i;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0, j = 0, k; i < n; i++) {
      scanf("%d", &k);
      if (k != 0) a[j++] = k;
    }
    for (int i = 0, j = 0, k; i < n; i++) {
      scanf("%d", &k);
      if (k != 0) b[j++] = k;
    }
    int y = f(b[0], n);
    bool flag = true;
    int num = n - 1, x = 0;
    while (num--) {
      if (b[x] != a[y]) {
        flag = false;
        break;
      }
      if (x == n - 2)
        x = 0;
      else
        x++;
      if (y == n - 2)
        y = 0;
      else
        y++;
    }
    printf(flag ? "YES\n" : "NO\n");
  }
  return 0;
}
