#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int main() {
  int n, m, s = 0, ans = 0, count1 = 0, i, j, k, x, y, l, r, p, q, c, i1, j1;
  scanf("%d", &n);
  j = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == 0)
      continue;
    else {
      a[j] = x;
      j++;
    }
  }
  j = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x == 0)
      continue;
    else {
      b[j] = x;
      j++;
    }
  }
  int flag = -1;
  if (n == 2 || n == 3) {
    printf("YES\n");
    return 0;
  }
  for (i = 0; i < n - 1; i++) {
    if (b[i] == a[0]) {
      flag = 1;
      for (j = 1; j < n - 1; j++) {
        if (b[(i + j) % (n - 1)] != a[j]) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 0 || flag == 1) break;
  }
  if (flag == 0)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
