#include <bits/stdc++.h>
using namespace std;
int a[1008611];
int b[1008611];
int main() {
  int n, i, j = 1, t, cou = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &t);
    if (t != 0) {
      a[j++] = t;
    } else
      cou++;
  }
  for (i = 1; i < j; i++) {
    a[i + j - 1] = a[i];
  }
  int k = 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &t);
    if (t != 0) {
      b[k++] = t;
    } else
      cou++;
  }
  if (cou == 0) {
    for (i = 1; i < j; i++) {
      if (a[i] != b[i]) {
        printf("NO\n");
        return 0;
      }
    }
    printf("YES\n");
    return 0;
  }
  for (i = 1; i < j; i++) {
    if (a[i] == b[1]) {
      for (k = 1; k < j; k++) {
        if (b[k] != a[i++]) {
          printf("NO\n");
          return 0;
        }
      }
      printf("YES\n");
      return 0;
    }
  }
}
