#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  vector<int> v1(n), v2(n);
  int pos1;
  for (int i = 0; i < n; i++) {
    cin >> v1[i];
    if (v1[i] == 1) pos1 = i;
  }
  int pos2;
  for (int i = 0; i < n; i++) {
    cin >> v2[i];
    if (v2[i] == 1) pos2 = i;
  }
  for (int i = 0; i < n; i++, pos1 = (pos1 + 1) % n, pos2 = (pos2 + 1) % n) {
    if (v1[pos1] == 0) pos1 = (pos1 + 1) % n;
    if (v2[pos2] == 0) pos2 = (pos2 + 1) % n;
    if (v1[pos1] != v2[pos2]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}
