#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 * 1000 + 10;
int a[maxn], parenta[maxn], parentb[maxn], n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) parenta[a[i]] = a[i - 1];
  parenta[a[0]] = a[n - 1];
  for (int i = 0; i < n; i++)
    if (parenta[i] == 0) parenta[i] = parenta[parenta[i]];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) parentb[a[i]] = a[i - 1];
  parentb[a[0]] = a[n - 1];
  for (int i = 0; i < n; i++)
    if (parentb[i] == 0) parentb[i] = parentb[parentb[i]];
  for (int i = 1; i < n; i++) {
    if (parenta[i] != parentb[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
