#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5;
int neighlist1[maxn + 10], neighlist2[maxn + 10];
int n, tmp;
vector<int> fi, sc;
int main() {
  memset(neighlist1, 0, sizeof neighlist1);
  memset(neighlist2, 0, sizeof neighlist2);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp > 0) fi.push_back(tmp);
  }
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp > 0) sc.push_back(tmp);
  }
  for (int i = 0; i < n - 1; i++) {
    neighlist1[fi[i]] = fi[(i + 1) % (n - 1)];
    neighlist2[sc[i]] = sc[(i + 1) % (n - 1)];
  }
  bool ans = true;
  for (int i = 0; i <= n; i++) ans &= (neighlist1[i] == neighlist2[i]);
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
}
