#include <bits/stdc++.h>
using namespace std;
long n, i, j, v[200005], v2[200005], ok0, oks;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> v[i];
    if (v[i] == 0) ok0 = 1;
  }
  for (i = 1; i <= n; i++) {
    cin >> v2[i];
    if (v2[i] != v[i]) oks = 1;
  }
  if (oks == 0) {
    cout << "YES\n";
    return 0;
  }
  if (ok0 == 0) {
    cout << "NO\n";
    return 0;
  }
  i = 1;
  while (v[i] == 0) i++;
  j = 1;
  while (v2[j] != v[i]) j++;
  int savi;
  savi = i;
  do {
    i++;
    if (i == n + 1) i = 1;
    while (v[i] == 0) {
      i++;
      if (i == n + 1) i = 1;
    }
    j++;
    if (j == n + 1) j = 1;
    while (v2[j] == 0) {
      j++;
      if (j == n + 1) j = 1;
    }
    if (v2[j] != v[i]) {
      cout << "NO\n";
      return 0;
    }
  } while (i != savi);
  cout << "YES\n";
  return 0;
}
