#include <bits/stdc++.h>
using namespace std;
int a[200000], b[200000];
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    if (x)
      a[i] = x;
    else
      i--;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> x;
    if (x)
      b[i] = x;
    else
      i--;
  }
  int i;
  for (i = 0; i < n - 1; i++) {
    if (a[i] == b[0]) break;
  }
  bool res = true;
  for (int j = 0; j < n - 1; j++, i++) {
    if (b[j] != a[i % (n - 1)]) res = false;
  }
  if (res)
    cout << "YES";
  else
    cout << "NO";
}
