#include <bits/stdc++.h>
using namespace std;
const int N = int(4e5);
int a[N], b[N], n, c[2 * N], cn;
int z[2 * N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i]) c[cn++] = b[i];
  }
  c[cn++] = -1;
  for (int i = 0; i < n; i++) {
    if (a[i]) {
      c[cn++] = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i]) {
      c[cn++] = a[i];
    }
  }
  int sz = n - 1;
  n = cn;
  int l, r;
  l = r = 0;
  z[0] = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < n && c[z[i]] == c[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) {
      r = i + z[i] - 1;
      l = i;
    }
    if (z[i] >= sz) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
  return 0;
}
