#include <bits/stdc++.h>
using namespace std;
void prepro() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(17);
  int n;
  cin >> n;
  vector<int> a, b;
  for (auto i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t != 0) a.push_back(t);
  }
  for (auto i = 0; i < n; i++) {
    int t;
    cin >> t;
    if (t != 0) b.push_back(t);
  }
  n--;
  int i = 0, j = 0;
  while (a[i] != 1) i++;
  while (b[j] != 1) j++;
  string out = "YES";
  for (auto t = 0; t < n; t++)
    if (a[(i + t) % n] != b[(j + t) % n]) out = "NO";
  cout << out;
  return 0;
}
