#include <bits/stdc++.h>
using namespace std;
const double PI =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286;
int n, a[400004], b[400004];
bool check() {
  int x = a[0];
  int i = 0;
  while (b[i] != x) i++;
  for (int j = i; j < n + i - 1; j++)
    if (a[j - i] != b[j]) return false;
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    a[n + i - 1] = a[i];
    if (a[i] == 0) i--;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
    b[n + i - 1] = b[i];
    if (b[i] == 0) i--;
  }
  if (check())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
