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