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