#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, x, y, i, j;
  bool fl;
  vector<int> A, B;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a);
    if (a)
      A.push_back(a);
    else
      fl = true;
  }
  for (i = 1; i <= n; ++i) {
    scanf("%d", &b);
    if (b) B.push_back(b);
  }
  if (!fl) {
    for (i = 0; i < (int)A.size(); ++i)
      if (A[i] != B[i]) {
        printf("NO\n");
        return 0;
      }
    printf("YES\n");
    return 0;
  }
  int t = A.size();
  for (i = 0; i < t; ++i) A.push_back(A[i]);
  t = B.size();
  for (i = 0; i < t; ++i) B.push_back(B[i]);
  for (i = 0; i < (int)A.size(); ++i)
    if (A[i] == 1) break;
  x = i;
  for (i = 0; i < (int)B.size(); ++i)
    if (B[i] == 1) break;
  y = i;
  for (i = x, j = y; i <= x + n - 1; ++i, ++j)
    if (A[i] != B[j]) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
  return 0;
}
