#include <bits/stdc++.h>
using namespace std;
int arr[200001];
int pos[200001];
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      arr[cnt] = x;
      cnt++;
    }
  }
  cnt = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      pos[cnt] = x;
      cnt++;
    }
  }
  n--;
  int j = 0;
  while (pos[j] != arr[0]) j++;
  for (int i = 0; i < n; i++) {
    if (pos[j] != arr[i]) {
      cout << "NO" << endl;
      return 0;
    }
    j++;
    if (j == n) j = 0;
  }
  cout << "YES" << endl;
}
