#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  n--;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 0) --i;
  }
  int principi;
  int b[n];
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    if (b[i] == 0) --i;
    if (b[i] == a[0]) principi = i;
  }
  bool bo = true;
  for (int i = 1; bo and i < n; ++i) {
    if (a[i] != b[(principi + i) % n]) bo = false;
  }
  if (bo)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
