#include <bits/stdc++.h>
using namespace std;
void preprocess(int arr[], int n) {
  int k = 0;
  for (int i = 0; i < n; ++i) {
    if (arr[i] != 0) arr[k++] = arr[i];
  }
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n], b[n];
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) scanf("%d", b + i);
  preprocess(a, n);
  preprocess(b, n);
  int j = 0;
  while (j < n) {
    if (b[j] == a[0]) break;
    ++j;
  }
  int flag = 0;
  for (int i = 0; i < n - 1; ++i, j = (j + 1) % (n - 1)) {
    if (a[i] != b[j]) {
      flag = 1;
      break;
    }
  }
  printf((flag == 1 ? "NO" : "YES"));
  return 0;
}
