#include <bits/stdc++.h>
bool is_shift(const std::vector<unsigned>& a, const std::vector<unsigned>& b) {
  for (int i = 0; i < 2 * a.size() - 1; i++) {
    for (int j = 0; j < b.size(); j++) {
      if (a[(i + j) % a.size()] != b[j]) break;
      if (j == b.size() - 1) return true;
    }
  }
  return false;
}
int main() {
  std::vector<unsigned> a, b;
  unsigned n;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    unsigned c;
    std::cin >> c;
    if (c != 0) a.push_back(c);
  }
  for (int i = 0; i < n; i++) {
    unsigned c;
    std::cin >> c;
    if (c != 0) b.push_back(c);
  }
  if (is_shift(a, b))
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
}
