#include <bits/stdc++.h>
using namespace std;
int n;
int a[200100];
int b[200100];
int d[200100];
void fix(int *c) {
  for (int(i) = (0); (i) < (n); ++(i))
    if (c[i] == 0) {
      int k = 0;
      for (int(j) = (i); (j) < (n); ++(j)) d[k++] = c[j];
      for (int(j) = (0); (j) < (i); ++(j)) d[k++] = c[j];
    }
  for (int(i) = (0); (i) < (n); ++(i)) c[i] = d[i];
  for (int(i) = (1); (i) < (n); ++(i))
    if (c[i] == 1) {
      int k = 0;
      d[k++] = 0;
      for (int(j) = (i); (j) < (n); ++(j)) d[k++] = c[j];
      for (int(j) = (1); (j) < (i); ++(j)) d[k++] = c[j];
    }
  for (int(i) = (0); (i) < (n); ++(i)) c[i] = d[i];
}
int main() {
  scanf("%d", &n);
  for (int(i) = (0); (i) < (n); ++(i)) scanf("%d", &a[i]);
  for (int(i) = (0); (i) < (n); ++(i)) scanf("%d", &b[i]);
  fix(a);
  fix(b);
  for (int(i) = (0); (i) < (n); ++(i))
    if (a[i] != b[i]) {
      puts("NO");
      return 0;
    }
  puts("YES");
}
