#include <bits/stdc++.h>
using namespace std;
void move_zero(vector<int>& v) {
  v.erase(find(v.begin(), v.end(), 0));
  auto one_pos = find(v.begin(), v.end(), 1);
  rotate(v.begin(), one_pos, v.end());
}
int main() {
  int n;
  cin >> n;
  vector<int> a1(n);
  vector<int> a2(n);
  for (int i = 0; i < n; ++i) {
    cin >> a1[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> a2[i];
  }
  move_zero(a1);
  move_zero(a2);
  if (a1 == a2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
