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