#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N], b[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) scanf("%d", b + i);
  vector<int> A;
  for (int i = 0; i < n; ++i)
    if (a[i]) A.push_back(a[i]);
  rotate(A.begin(), min_element(A.begin(), A.end()), A.end());
  vector<int> B;
  for (int i = 0; i < n; ++i)
    if (b[i]) B.push_back(b[i]);
  rotate(B.begin(), min_element(B.begin(), B.end()), B.end());
  printf(A == B ? "YES\n" : "NO\n");
}
