#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 100;
int a[M], b[M], n;
int main() {
  cin >> n;
  vector<int> v, w;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 0) v.push_back(a[i]);
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) w.push_back(b[i]);
  }
  int ix;
  for (int i = 0; i < v.size(); i++) {
    if (v[0] == w[i]) {
      ix = i;
      break;
    }
  }
  int q[n - 1];
  for (int i = 0; i < v.size(); i++) {
    q[(i + ix) % (n - 1)] = v[i];
  }
  for (int i = 0; i < n - 1; i++)
    if (q[i] != w[i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
