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