#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int statue[n - 1];
  int first_statue;
  int first_wanted;
  int tmp;
  int now = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp != 0) {
      statue[now] = tmp;
      now++;
    }
    if (tmp == 1) {
      first_statue = now - 1;
    }
  }
  int wanted[n - 1];
  now = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp != 0) {
      wanted[now] = tmp;
      now++;
    }
    if (tmp == 1) {
      first_wanted = now - 1;
    }
  }
  int d = 0;
  bool result = true;
  while (d < n - 1 && result) {
    if (statue[(first_statue + d) % (n - 1)] !=
        wanted[(first_wanted + d) % (n - 1)]) {
      result = false;
    }
    d++;
  }
  if (result) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
