#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    if (a[i] == 0) i--;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
    if (b[i] == 0) i--;
  }
  n--;
  for (int i = 0; i < n; i++) {
    if (b[i] != 1) continue;
    int x = 0;
    for (x = 0; x < n; x++) {
      if (a[x] == 1) break;
    }
    int j = (i + 1) % (n), q = (x + 1) % (n);
    while (1) {
      if (b[j] == 1 && a[q] == 1) break;
      if (a[q] != b[j]) {
        cout << "NO";
        return 0;
      }
      j++;
      q++;
      q %= n;
      j %= (n);
    }
    cout << "YES";
  }
}
