#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 100;
long long n, a[M], nxt[M];
bool mark = false;
vector<long long> v, t;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = (0); i <= (n - 1); i++) {
    cin >> a[i];
    if (a[i]) v.push_back(a[i]);
  }
  for (long long i = (0); i <= (n - 2); i++) nxt[v[i]] = v[(i + 1) % (n - 1)];
  for (long long i = (0); i <= (n - 1); i++) {
    cin >> a[i];
    if (a[i]) t.push_back(a[i]);
  }
  for (long long i = (0); i <= (n - 2); i++) {
    if (nxt[t[i]] != t[(i + 1) % (n - 1)]) mark = true;
  }
  if (!mark)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
