#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[200000], b[200000];
  int n, x, y;
  cin >> 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--;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[0] == b[i]) {
      y = i;
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (a[i] != b[(y + i) % (n - 1)]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
