#include <bits/stdc++.h>
using namespace std;
int toNumber(string s) {
  int Number;
  if (!(istringstream(s) >> Number)) Number = 0;
  return Number;
}
string toString(int number) {
  ostringstream ostr;
  ostr << number;
  return ostr.str();
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  for (int i = 0; i < (int)(n); i++) cin >> b[i];
  int i = 0;
  if (a[i] == 0) i++;
  int j = 0;
  while (b[j] != a[i]) j++;
  int vi0a = 0, vi0b = 0;
  for (int k = 0; k < (int)(n); k++) {
    if (a[(i + k) % n] == 0) vi0a++;
    if (b[(j + k) % n] == 0) vi0b++;
    if (a[(i + k + vi0a) % n] != b[(j + k + vi0b) % n]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}
