#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  scanf("%d\n", &n);
  vector<int> desired;
  vector<int> fact;
  bool fail = true;
  desired.reserve(n * 2 + 1);
  fact.reserve(n * 2 + 1);
  int k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    if (k != 0) {
      fact.push_back(k);
    }
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &k);
    if (k != 0) {
      desired.push_back(k);
    }
  }
  for (int i = 0; i < n; i++) {
    fact.push_back(fact[i]);
    if (equal(desired.begin(), desired.end(), fact.begin() + i)) {
      fail = false;
      break;
    }
  }
  printf(fail ? "NO" : "YES");
  return 0;
}
