#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int main() {
  long long n, i, j;
  cin >> n;
  vector<long long> v, u;
  long long t;
  for (i = 0; i < n; i++) {
    cin >> t;
    if (t != 0) v.push_back(t);
  }
  for (i = 0; i < n; i++) {
    cin >> t;
    if (t != 0) {
      u.push_back(t);
      if (t == v[0]) j = u.size() - 1;
    }
  }
  i = 0;
  while (i < (n - 1) && v[i] == u[j]) {
    i++;
    j = (j + 1) % (n - 1);
  }
  if (i == (n - 1))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
