#include <bits/stdc++.h>
using namespace std;
long long r, c, n, len, l, z, x, y, m, t, k, ans;
int a[200005], b[200005];
map<int, int> ind;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ind[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int ii = 0;
  if (b[ii] == 0) {
    ii++;
  }
  x = ind[b[ii]];
  for (int i = ii; i < n; i++) {
    if (x >= n) x = 0;
    if (b[i] == 0) continue;
    if (a[x] == 0) x++;
    if (x >= n) x = 0;
    if (b[i] != a[x]) {
      cout << "No";
      return 0;
    }
    x++;
  }
  cout << "Yes";
}
