#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, a[N], b[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int i = 0;
  while (a[i] == 0) {
    i++;
  }
  int j = 0;
  while (b[j] != a[i]) {
    j++;
  }
  for (int k = 0; k < n; k++) {
    i = (i + 1) % n;
    j = (j + 1) % n;
    if (a[i] == 0) {
      i = (i + 1) % n;
    }
    if (b[j] == 0) {
      j = (j + 1) % n;
    }
    if (a[i] != b[j]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
