#include <bits/stdc++.h>
using namespace std;
int const siz = 1e9, bound = 5e5, mod = siz + 7;
long long const cnt = 1e18;
int aa[bound], ee[bound];
int main() {
  int n;
  scanf("%d", &n);
  int j = 0, sz;
  for (int(i) = 0; (i) < (n); (i)++) {
    int a;
    scanf("%d", &a);
    if (a) aa[j++] = a;
  }
  sz = j;
  j = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    int a;
    scanf("%d", &a);
    if (a) ee[j++] = a;
  }
  int idx = find(aa, aa + n, ee[0]) - aa;
  for (int i = 0; i < j; idx = (idx + 1) % sz, i++) {
    if (aa[idx] != ee[i]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
