#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int id;
    cin >> id;
    if (id) a.push_back(id);
  }
  for (int i = 0; i < n; i++) {
    int id;
    cin >> id;
    if (id) b.push_back(id);
  }
  int pos = 0;
  for (int i = 0; i < n - 1; i++)
    if (a[0] == b[i]) pos = i;
  for (int i = 0; i < n - 1; i++)
    if (a[i] != b[(i + pos) % (n - 1)]) {
      cout << "NO\n";
      return 0;
    }
  cout << "YES\n";
}
