#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[200009], b[200009], ii = 0;
  for (int i = 0; i < n; i++) {
    int tt;
    cin >> tt;
    if (tt) a[ii++] = tt;
  }
  ii = 0;
  for (int i = 0; i < n; i++) {
    int tt;
    cin >> tt;
    if (tt) b[ii++] = tt;
  }
  map<int, pair<int, int> > mp;
  for (int i = 0; i < n - 1; i++) {
    int t1, t2;
    if (!i)
      t1 = a[n - 2];
    else
      t1 = a[i - 1];
    if (i == n - 2)
      t2 = a[0];
    else
      t2 = a[i + 1];
    mp[a[i]] = make_pair(t1, t2);
  }
  for (int i = 0; i < n - 1; i++) {
    int t1, t2;
    if (!i)
      t1 = b[n - 2];
    else
      t1 = b[i - 1];
    if (i == n - 2)
      t2 = b[0];
    else
      t2 = b[i + 1];
    if (b[i] && (t1 != mp[b[i]].first || t2 != mp[b[i]].second)) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
