#include <bits/stdc++.h>
using namespace std;
int n, a[401000], b[401000];
int r1[201000], r2[201000];
int main(int argc, char **argv) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    a[i + n] = a[i];
  }
  for (int j = 0; j < n; ++j) {
    scanf("%d", b + j);
    b[j + n] = b[j];
  }
  int last = -1, l = -1;
  int t1 = 0, t2 = 0;
  for (int i = 0; i < 401000; ++i) {
    if (a[i] != 0) {
      ++t1;
      if (t1 > n) continue;
      if (last == -1)
        last = a[i];
      else {
        r1[last] = a[i];
        last = a[i];
      }
    }
    if (b[i] != 0) {
      ++t2;
      if (t2 > n) continue;
      if (l == -1)
        l = b[i];
      else {
        r2[l] = b[i];
        l = b[i];
      }
    }
  }
  for (int i = 0; i < n; ++i)
    if (r1[i] != r2[i]) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
