#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int n, a[N], b[N], pos, pos1, cnt, l[N], r[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (!a[i]) pos = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (!b[i]) pos1 = i;
  }
  while (pos < n) {
    swap(a[pos], a[pos + 1]);
    pos++;
  }
  while (pos1 < n) {
    swap(b[pos1], b[pos1 + 1]);
    pos1++;
  }
  n--;
  a[0] = a[n];
  a[n + 1] = a[1];
  b[0] = b[n];
  b[n + 1] = b[1];
  for (int i = 1; i <= n; i++) {
    l[a[i]] = a[i - 1];
    r[a[i]] = a[i + 1];
  }
  for (int i = 1; i <= n; i++) {
    if (b[i - 1] != l[b[i]] || b[i + 1] != r[b[i]]) printf("NO"), exit(0);
  }
  printf("YES");
  return 0;
}
