#include <bits/stdc++.h>
using namespace std;
int n, i, f, c, x[200000], y[200000];
int main() {
  cin >> n;
  for (i = 0; i < n - 1; i++) {
    cin >> x[i];
    if (x[i] == 0) i--;
  }
  for (i = 0; i < n - 1; i++) {
    cin >> y[i];
    if (y[i] == 0) i--;
  }
  for (i = 0; i < n - 1; i++) {
    if (x[i] == y[0]) {
      c = i;
      break;
    }
  }
  for (i = 0; i < n - 1; i++) {
    if (x[(i + c) % (n - 1)] == y[i]) {
      continue;
    }
    f = 1;
    break;
  }
  if (!f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
