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