#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, *a, *b, i, p, z;
  cin >> n;
  a = new int[n];
  b = new int[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0) {
      z = i;
    }
  }
  if (n <= 3) {
    cout << "YES" << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (a[i] == b[0]) {
      p = i;
      break;
    }
  }
  for (i = 0; i < n; i++) {
    if (a[p] == 0) {
      p++;
      p %= n;
    }
    if (b[i] != 0) {
      if (b[i] != a[p]) {
        cout << "NO" << endl;
        return 0;
      }
      p++;
      p %= n;
    }
  }
  cout << "YES" << endl;
  return 0;
}
