#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 9;
const long long inf = (1ll << 60);
const long long mod = 1e9 + 7;
int n, i1, i2, a[MX], b[MX];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!a[i]) i1 = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (!b[i]) i2 = i;
  }
  int m = b[(i2 + 1) % n];
  while (m != a[(i1 + 1) % n]) {
    swap(a[i1], a[(i1 + 1) % n]);
    i1 = (i1 + 1) % n;
  }
  bool ok = 1;
  for (int i = 0; i < n + 1; i++) {
    i1 = (i1 + 1) % n;
    i2 = (i2 + 1) % n;
    if (a[i1] != b[i2]) ok = 0;
  }
  if (ok)
    puts("YES");
  else
    puts("NO");
}
