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