#include <bits/stdc++.h>
const int MAX_N = (int)1e5 + 123;
const double eps = 1e-6;
const int inf = (int)1e9 + 123;
using namespace std;
int n;
vector<int> a, b;
int main() {
  cin >> n;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    if (x) a.push_back(x);
  }
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    if (x) b.push_back(x);
  }
  vector<int> nw;
  while (a.back() != b.back()) {
    nw.push_back(a.back());
    a.pop_back();
  }
  reverse(nw.begin(), nw.end());
  for (auto i : a) nw.push_back(i);
  cout << (nw == b ? "YES" : "NO");
  return 0;
}
