#include <bits/stdc++.h>
using namespace std;
int ary1[400010], ary2[400010], start1, start2, idx, n;
vector<int> myvec, newvec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ary1[i];
    ary1[n + i] = ary1[i];
    if (ary1[i] == 1) start1 = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> ary2[i];
    ary2[n + i] = ary2[i];
    if (ary2[i] == 1) start2 = i;
  }
  idx = start1 + 1;
  while (ary1[idx] != 1) {
    if (ary1[idx] != 0) myvec.push_back(ary1[idx]);
    ++idx;
  }
  idx = start2 + 1;
  while (ary2[idx] != 1) {
    if (ary2[idx] != 0) newvec.push_back(ary2[idx]);
    ++idx;
  }
  if (myvec == newvec)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
  return 0;
}
