#include <bits/stdc++.h>
using namespace std;
void Filework(void) {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
int a[500001], b[200001];
int main() {
  int n;
  int i;
  int index;
  int pos;
  string s;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) pos = i;
  }
  for (i = pos; i <= n - 1; i++) a[i] = a[i + 1];
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 0) pos = i;
  }
  for (i = pos; i <= n - 1; i++) b[i] = b[i + 1];
  n--;
  for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];
  for (i = 1; i <= n; i++) {
    if (a[i] == b[1]) {
      index = i;
      break;
    }
  }
  for (i = 0; i <= n - 1; i++) {
    if (a[index + i] != b[i + 1]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
