#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int n;
bool f;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (v) a.push_back(v);
  }
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (v) b.push_back(v);
  }
  if (a.size() != b.size())
    f = true;
  else {
    int d;
    for (d = 1; d < a.size(); d++)
      if (a[0] == b[d]) break;
    for (int i = 0; i < a.size(); i++) f |= (a[i] != b[(i + d) % a.size()]);
  }
  cout << (f ? "NO" : "YES") << endl;
  return 0;
}
