#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a, b;
  a.reserve(n);
  b.reserve(n);
  for (int i = 0; i < n; ++i) {
    int el;
    scanf("%d", &el);
    if (el) {
      a.push_back(el);
    }
  }
  for (int i = 0; i < n; ++i) {
    int el;
    scanf("%d", &el);
    if (el) {
      b.push_back(el);
    }
  }
  n--;
  int start = 0;
  for (int i = 0; i < n; ++i) {
    if (b[i] == a[0]) {
      start = i;
      break;
    }
  }
  bool f = true;
  for (int i = 0; i < n; ++i) {
    if (b[start] != a[i]) {
      f = false;
      break;
    }
    start = (start + 1) % n;
  }
  if (f) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
