#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, x, rt;
  cin >> n;
  n -= 1;
  k = 0;
  int arr[n + 7], brr[n + 7];
  while (k < n) {
    cin >> x;
    if (x) {
      arr[k] = x;
      k++;
    }
  }
  k = 0;
  while (k < n) {
    cin >> x;
    if (x) {
      brr[k] = x;
      k++;
    }
    if (x == arr[0]) rt = k - 1;
  }
  int cnt = 0;
  for (int j = 0; j < n; j++) {
    if (arr[j] == brr[(j + rt) % (n)]) cnt++;
  }
  if (cnt == n) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
