#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, max;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    if (a[i] == 0) i--;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
    if (b[i] == 0) i--;
    if (b[i] == a[0]) max = i;
  }
  for (int i = 0, j = max; i < n - 1; i++, j++) {
    if (a[i] != b[j]) {
      cout << "No";
      return 0;
    }
    if (j == n - 2) j = -1;
  }
  cout << "Yes";
  return 0;
}
