#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[200000], b[200000];
  int i = 0;
  bool f = 1;
  while (i < n - 1) {
    cin >> a[i];
    if (a[i] != 0)
      i++;
    else
      f = 0;
  }
  if (f) cin >> i;
  int v = a[0], p;
  i = 0;
  f = 1;
  while (i < n - 1) {
    cin >> b[i];
    if (b[i] == v) p = i;
    if (b[i] != 0)
      i++;
    else
      f = 0;
  }
  if (f) cin >> i;
  f = 1;
  for (int i = 0; i < n - 1; i++)
    if (a[i] != b[(p + i) % (n - 1)]) f = 0;
  if (f)
    cout << "YES\n";
  else
    cout << "NO\n";
}
