#include <bits/stdc++.h>
constexpr long long inf = (long long)1e9 + 7ll;
char buff[(int)2e6 + 17];
inline void config_io(const bool& __fastio) {
  if (__fastio) {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
  if (!std::string("").empty()) {
    assert(
        freopen(""
                ".in",
                "r", stdin));
    assert(
        freopen(""
                ".out",
                "w", stdout));
  }
}
using namespace std;
const int maxn = (int)2e5 + 17;
int n;
int a[maxn], b[maxn];
int nxt[maxn];
int main() {
  config_io(false);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  for (int i = 0; i < n; ++i) {
    if (a[(i + 1) % n] == 0)
      nxt[a[i]] = a[(i + 2) % n];
    else
      nxt[a[i]] = a[(i + 1) % n];
  }
  for (int i = 0; i < n; ++i)
    if (b[i] != 0) {
      int t;
      if (b[(i + 1) % n] == 0)
        t = b[(i + 2) % n];
      else
        t = b[(i + 1) % n];
      if (t != nxt[b[i]]) {
        printf("NO\n");
        return 0;
      }
    }
  printf("YES\n");
  return 0;
}
