#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int A[n - 1];
  int B[n - 1];
  int c = 0, d = 0, a, b;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a != 0) {
      A[c] = a;
      c++;
    }
  }
  for (int j = 0; j < n; j++) {
    cin >> b;
    if (b != 0) {
      B[d] = b;
      d++;
    }
  }
  int index = 0, index2 = 0;
  for (int s = 0; s < n - 1; s++) {
    if (A[s] != 0) {
      index = s;
      break;
    }
  }
  for (int g = 0; g < n - 1; g++) {
    if (B[g] == A[index]) {
      index2 = g;
      break;
    }
  }
  bool possible = true;
  for (int w = 0; w < n; w++) {
    if (A[index] == B[index2]) {
      if (index == n - 2) {
        index = 0;
      } else
        index++;
      if (index2 == n - 2) {
        index2 = 0;
      } else
        index2++;
    } else
      possible = false;
  }
  if (possible)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
