#include <bits/stdc++.h>
using namespace std;
int a[200003], b[200003], ch[200003];
void Do() {
  int n, f = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 0) f = 1;
    if (f) a[i] = a[i + 1];
  }
  f = 0;
  for (int i = 0; i < n - 1; i++) {
    if (b[i] == 0) f = 1;
    if (f) b[i] = b[i + 1];
  }
  int beg = a[0], desire;
  ch[0] = a[0];
  for (int i = 0; i < n - 1; i++)
    if (b[i] == beg) desire = i;
  int ind = 1;
  for (int i = desire + 1; i < n - 1; i++) {
    ch[ind++] = b[i];
    if (ind == n - 1) break;
  }
  if (ind != n - 1) {
    for (int i = 0;; i++) {
      ch[ind++] = b[i];
      if (ind == n - 1) break;
    }
  }
  bool flag = true;
  for (int i = 0; i < n - 1; i++)
    if (a[i] != ch[i]) flag = false;
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  Do();
  return 0;
}
