#include <bits/stdc++.h>
using namespace std;
bool tr(long long k) {
  for (long long j = 2; j <= sqrt(k); j++) {
    if (k % j == 0) return false;
  }
  return true;
}
int main() {
  long long n, x, y, t = 0, m, c, k, d, r, p, q;
  cin >> n;
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) a.push_back(x);
  }
  vector<long long> b;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) b.push_back(x);
  }
  long long i = 0, l = 1, j = 1;
  for (i = 0; i < a.size(); i++) {
    if (b[0] == a[i]) break;
  }
  if (a.size() != b.size() || i == n) {
    cout << "NO";
    return 0;
  }
  i++;
  while (l != a.size()) {
    i = i % a.size();
    if (a[i] != b[j]) {
      break;
    }
    l++;
    i++;
    j++;
  }
  if (l != a.size())
    cout << "NO";
  else
    cout << "YES";
}
