#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> a, b;
int main() {
  unsigned long long n, ap, m = 0, k, j = 0;
  cin >> n;
  for (unsigned long long i = 0; i < n; i++) {
    cin >> ap;
    a.push_back(ap);
  }
  for (unsigned long long i = 0; i < n; i++) {
    cin >> ap;
    b.push_back(ap);
  }
  for (unsigned long long i = 0; i < a.size(); i++) {
    if (a[i] == 0) a.erase(a.begin() + i);
  }
  for (unsigned long long i = 0; i < b.size(); i++) {
    if (b[i] == 0) b.erase(b.begin() + i);
  }
  if (a.size() == n) {
    cout << "NO";
    return 0;
  }
  for (unsigned long long i = 0; i < b.size(); i++) {
    if (b[i] == a[0]) {
      k = i;
      break;
    }
  }
  for (unsigned long long l = 0, i = k; l < b.size(); l++, i++) {
    if (i == b.size()) i = 0;
    if (a[j++] == b[i]) m++;
  }
  if (m == b.size())
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
