#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LLINF = 1LL << 62;
const int mod = 1000000007;
int k, i, j, n, m, x, mna, mnb, turns, posa, posb;
int a[200005];
int b[200005];
int main() {
  scanf("%d", &k);
  mna = 1;
  mnb = 1;
  for (i = 1; i <= k; i++) {
    scanf("%d", &x);
    if (x != 0) a[++n] = x;
    if (a[n] < a[mna]) mna = n;
  }
  for (i = 1; i <= k; i++) {
    scanf("%d", &x);
    if (x != 0) b[++m] = x;
    if (b[m] < b[mnb]) mnb = m;
  }
  if (m != n) {
    puts("NO");
    return 0;
  }
  if (n == 0) {
    puts("YES");
    return 0;
  }
  posa = mna;
  posb = mnb;
  while (1) {
    if (posa == mna) turns++;
    if (turns >= 2) break;
    if (a[posa] != b[posb]) {
      puts("NO");
      return 0;
    }
    posa++;
    if (posa > n) posa -= n;
    posb++;
    if (posb > m) posb -= n;
  }
  puts("YES");
  return 0;
}
