#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> r(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = 0; i < n; ++i) cin >> r[i];
  vector<int> red;
  vector<int> red2;
  vector<int> nbr(n);
  vector<int> nbr2(n);
  for (auto num : v)
    if (num != 0) red.push_back(num);
  for (int i = 0; i < n - 1; ++i) {
    nbr[red[i]] = red[(i + 1) % (n - 1)];
  }
  for (auto num : r)
    if (num != 0) red2.push_back(num);
  for (int i = 0; i < n - 1; ++i) {
    nbr2[red2[i]] = red2[(i + 1) % (n - 1)];
  }
  bool ans = true;
  for (int i = 0; i < n && ans; ++i) {
    int a = r[i];
    if (nbr[a] != nbr2[a]) ans = false;
  }
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
