#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp) a.push_back(tmp);
  }
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp) b.push_back(tmp);
  }
  int i = 0, j = 0;
  while (a[0] != b[j]) j++;
  n--;
  while (i < n) {
    if (a[i] != b[j]) {
      cout << "NO\n";
      return 0;
    }
    i++, j++;
    if (j == n) j = 0;
  }
  cout << "YES\n";
}
