#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, x;
  cin >> n;
  vector<int> bef;
  vector<int> aft;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) bef.push_back(x);
  }
  int first = bef[0];
  int idx = -1;
  int idx_find = -1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) {
      idx++;
      if (x == first) idx_find = idx;
      aft.push_back(x);
    }
  }
  if (idx_find == -1) {
    cout << "NO" << endl;
    return 0;
  }
  int bef_idx = idx_find;
  for (int i = idx_find; i < aft.size(); i++) {
    if (aft[i] != bef[i - idx_find]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int i = 0; i < idx_find; i++) {
    if (aft[i] != bef[i + (-idx_find + aft.size())]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
  return 0;
}
