#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v1(n - 1), v2(n - 1);
  bool ok = 0;
  for (int i = 1; i < n; i++) {
    cin >> v1[i - 1];
    if (v1[i - 1] == 0) {
      cin >> v1[i - 1];
      ok = 1;
    }
  }
  int x;
  if (!ok) cin >> x;
  ok = 0;
  for (int i = 1; i < n; i++) {
    cin >> v2[i - 1];
    if (v2[i - 1] == 0) {
      cin >> v2[i - 1];
      ok = 1;
    }
  }
  if (!ok) cin >> x;
  for (int i = 0; i < v2.size(); i++) v1.push_back(v1[i]);
  ok = 0;
  for (int i = 0; i < v2.size(); i++) {
    int k = 0;
    while (k < v2.size() && v2[k] == v1[i + k]) k++;
    if (k == v2.size()) {
      ok = 1;
      break;
    }
  }
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}
