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