#include <bits/stdc++.h>
using namespace std;
struct sort_pred {
  bool operator()(const std::pair<long, long> &left,
                  const std::pair<long, long> &right) {
    return left.second < right.second;
  }
};
int main() {
  long n;
  cin >> n;
  vector<long> a;
  vector<long> b;
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp != 0) {
      a.push_back(temp);
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (temp != 0) {
      b.push_back(temp);
    }
  }
  long a1a, b1b;
  if (a.size() != b.size()) {
    cout << "NO";
    return 0;
  }
  n = a.size();
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 1) a1a = i;
  }
  for (int i = 0; i < b.size(); i++) {
    if (b[i] == 1) b1b = i;
  }
  bool flag = true;
  for (int i = 0; i < n; a1a++, b1b++, i++) {
    if (a1a == n) a1a = a1a % n;
    if (b1b == n) b1b = b1b % n;
    if (a[a1a] != b[b1b]) flag = false;
  }
  if (flag == true)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
