#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int n, a[maxn], b[maxn], nexta[maxn], nextb[maxn];
bool cp() {
  for (int i = 1; i <= n; i++)
    if (nexta[i] != nextb[i]) return false;
  return true;
}
int main() {
  cin >> n;
  int d = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[d];
    if (a[d] != 0) d++;
  }
  d = 1;
  for (int i = 1; i <= n; i++) {
    cin >> b[d];
    if (b[d] != 0) d++;
  }
  n--;
  for (int i = 1; i <= n - 1; i++) {
    nexta[a[i]] = a[i + 1];
    nextb[b[i]] = b[i + 1];
  }
  nexta[a[n]] = a[1];
  nextb[b[n]] = b[1];
  if (cp())
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
