#include <bits/stdc++.h>
using namespace std;
int a[200001], b[200001];
int main() {
  int n, i, j;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  if (a[1] == 0)
    i = 2;
  else
    i = 1;
  for (j = 1; j <= n; j++)
    if (b[j] == a[i]) break;
  int num = 1;
  while (num < n - 1) {
    i++;
    j = (j % n) + 1;
    if (a[i] == 0) i++;
    if (b[j] == 0) j = (j % n) + 1;
    ;
    num++;
    if (a[i] != b[j]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}
