#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> ai;
  vector<int> bi;
  int firstlaw = -1;
  for (int i = 0; i < n; i++) {
    int cura;
    cin >> cura;
    if (cura != 0) {
      ai.push_back(cura);
    }
  }
  firstlaw = ai[0];
  int secondlaw = -1;
  for (int i = 0; i < n; i++) {
    int curb;
    cin >> curb;
    if (curb != 0) {
      bi.push_back(curb);
    }
    if (curb == firstlaw) secondlaw = (bi.size() - 1);
  }
  bool validate = true;
  for (int i = secondlaw; i < secondlaw + n - 1; i++) {
    if (bi[i % (n - 1)] != ai[i - secondlaw]) validate = false;
  }
  if (validate)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
