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