#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long int> a, b;
  for (long long i = 0; i < n; i++) {
    long long d;
    cin >> d;
    if (d) a.push_back(d);
  }
  for (long long i = 0; i < n; i++) {
    long long d;
    cin >> d;
    if (d) b.push_back(d);
  }
  long long l = 0;
  while (a[l] != b[0]) l++;
  for (long long i = 0; i < n - 1; i++) {
    if (b[i] != a[l]) {
      cout << "No";
      return;
    }
    l++;
    l %= (n - 1);
  }
  cout << "Yes";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  long long t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  cin.get();
  return 0;
}
