#include <bits/stdc++.h>
using namespace std;
int i, j, k, m, n, dp[200001], r[200001];
int main() {
  ios::sync_with_stdio(false);
  cout.precision(10);
  cout << fixed;
  cin >> n;
  for (i = 1; i < n; ++i) {
    cin >> dp[i];
    if (!dp[i]) i--;
  }
  for (i = 1; i < n; ++i) {
    cin >> r[i];
    if (!r[i]) i--;
  }
  int st = 1, dr;
  for (i = 1; i < n; ++i)
    if (r[i] == dp[1]) {
      dr = i;
      break;
    }
  for (st = 1; st < n; ++st) {
    if (dp[st] != r[dr]) {
      cout << "No";
      return 0;
    } else
      ++dr;
    if (dr == n) dr = 1;
  }
  cout << "Yes";
  return 0;
}
