#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  vector<long> a(n), b(n);
  for (long i = 0; i < n; i++) scanf("%d", &a[i]);
  for (long i = 0; i < n; i++) scanf("%d", &b[i]);
  long i = 0, j = 0;
  if (a[j] == 0) j++;
  while (b[i] != a[j]) i++;
  long i0 = i;
  bool f = true;
  i++;
  j++;
  while (true) {
    if (i >= b.size()) i = 0;
    if (j >= a.size()) j = 0;
    if (b[i] == a[j]) {
      if (i == i0) break;
      i++;
      j++;
    } else if (b[i] == 0)
      i++;
    else if (a[j] == 0)
      j++;
    else {
      f = false;
      break;
    }
  }
  if (f)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
