#include <bits/stdc++.h>
using namespace std;
int n, a;
vector<int> b, ko;
int main() {
  cin >> n;
  b.resize(n + 1);
  ko.resize(n + 1);
  n--;
  for (int k = 1; k <= n; k++) {
    cin >> a;
    if (a == 0) cin >> a;
    ko[a] = k;
  }
  for (int k = 1; k <= n; k++) {
    cin >> b[k];
    if (b[k] == 0) cin >> b[k];
  }
  if (ko[b[1]] == 1) {
    if (ko[b[n]] != n) {
      cout << "NO";
      return 0;
    }
  } else if (ko[b[1]] - ko[b[n]] > 1) {
    cout << "NO";
    return 0;
  }
  for (int k = 2; k <= n; k++) {
    if (ko[b[k]] == 1) {
      if (ko[b[k - 1]] != n) {
        cout << "NO";
        return 0;
      }
    } else if (ko[b[k]] - ko[b[k - 1]] > 1) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
