#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(7);
  int n, a0 = 0, b0 = 0;
  cin >> n;
  std::vector<int> a(n), b(n);
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      a0 = i;
    }
  }
  while (a0 > 0) {
    std::swap(a[a0], a[a0 - 1]);
    --a0;
  }
  for (size_t i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0) {
      b0 = i;
    }
  }
  while (b0 > 0) {
    std::swap(b[b0], b[b0 - 1]);
    --b0;
  }
  int pos = 0;
  for (size_t i = 0; i < n; i++) {
    if (b[i] == a[1]) {
      pos = i;
    }
  }
  int inend = n - pos;
  std::cout << (vector<int>(a.begin() + 1, a.begin() + 1 + inend) ==
                            vector<int>(b.begin() + pos, b.end()) &&
                        vector<int>(a.begin() + 1 + inend, a.end()) ==
                            vector<int>(b.begin() + 1, b.begin() + pos)
                    ? "YES"
                    : "NO")
            << std::endl;
  return 0;
}
