#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N], c[N] = {0};
int main() {
  scanf("%d", &n);
  int vt, fi;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 0) vt = i;
  }
  if (b[0] == 0) {
    for (int i = 0; i < n; i++)
      if (a[i] == b[1]) vt = i;
    int k = 1;
    for (int i = vt; i < n; i++)
      if (a[i] != 0) c[k++] = a[i];
    for (int i = 0; i < vt; i++)
      if (a[i] != 0) c[k++] = a[i];
    for (int i = 0; i < n; i++)
      if (c[i] != b[i]) {
        printf("NO");
        return 0;
      }
    printf("YES");
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (a[i] == b[0]) fi = i;
  c[vt] = 0;
  int k = 0;
  for (int i = fi; i < n; i++)
    if (k == vt) {
      k++;
      i--;
    } else if (a[i] != 0)
      c[k++] = a[i];
  for (int i = 0; i < fi; i++)
    if (k == vt) {
      k++;
      i--;
    } else if (a[i] != 0)
      c[k++] = a[i];
  for (int i = 0; i < n; i++)
    if (b[i] != c[i]) {
      printf("NO");
      return 0;
    }
  printf("YES");
}
