#include <bits/stdc++.h>
using namespace std;
int a[200005 + 10], b[200005 + 10];
int main() {
  int i, j, n, m, temp, pos;
  bool ans = true;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  if (a[1] == 0)
    temp = a[2];
  else
    temp = a[1];
  for (i = 1; i <= n; i++) {
    if (b[i] == temp) {
      pos = i;
      break;
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == 0) continue;
    if (b[pos] == 0) pos++;
    if (pos > n) pos++;
    if (b[pos] != a[i]) ans = false;
    pos++;
    if (b[pos] == 0) pos++;
    if (pos > n) pos = 1;
  }
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
