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