#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  std::vector<int> a(n - 1);
  std::vector<int> b(n - 1);
  for (int i = 0, ind = 0; i < n; i++) {
    cin >> a[ind];
    if (a[ind]) ind++;
  }
  for (int i = 0, ind = 0; i < n; i++) {
    cin >> b[ind];
    if (b[ind]) ind++;
  }
  int ind = 0;
  n--;
  for (ind = 0; ind < n; ind++)
    if (b[ind] == a[0]) break;
  bool good = true;
  for (int i = 0; i < n; i++, ind++) {
    if (ind == n) ind = 0;
    if (a[i] != b[ind]) {
      good = false;
      break;
    }
  }
  cout << (good ? "YES" : "NO") << "\n";
}
