#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool readInteger(T& x) {
  char c, r = 0, n = 0;
  x = 0;
  for (;;) {
    c = getchar();
    if ((c < 0) && (!r))
      return (0);
    else if ((c == '-') && (!r))
      n = 1;
    else if ((c >= '0') && (c <= '9'))
      x = x * 10 + c - '0', r = 1;
    else if (r)
      break;
  }
  if (n) x = -x;
  return (1);
}
template <typename T, T MOD>
struct ModInt {
  T value;
  ModInt() : value(0) {}
  ModInt(T x) {
    x %= MOD;
    if (x < 0) x += MOD;
    value = x;
  }

 private:
  T __________________(T ___, T ____) {
    if (!____) return ___;
    return __________________(____, ___ % ____);
  }
  T _____________(T _, T __, T ____, T ___) {
    T _____, ______, _______ = ____ - _;
    assert(!(_______ % __________________(__, ___)));
    for (_____ = ______ = 0; _____ - ______ != _______;) {
      _____ = (_______ + ______ + __ - 1) / __ * __;
      ______ = (_____ - _______ + ___ - 1) / ___ * ___;
    }
    return _____ + _;
  }

 public:
  ModInt& operator+=(ModInt x) {
    value += x.value;
    if (value >= MOD) value -= MOD;
    return *this;
  }
  ModInt& operator-=(ModInt x) {
    value -= x.value;
    if (value < 0) value += MOD;
    return *this;
  }
  ModInt& operator*=(ModInt x) {
    value *= x.value;
    value %= MOD;
    return *this;
  }
  ModInt& operator/=(ModInt x) {
    x.invert();
    return *this *= x;
  }
  ModInt operator+(ModInt x) const {
    ModInt o = *this;
    o += x;
    return o;
  }
  ModInt operator-(ModInt x) const {
    ModInt o = *this;
    o -= x;
    return o;
  }
  ModInt operator*(ModInt x) const {
    ModInt o = *this;
    o *= x;
    return o;
  }
  ModInt operator/(ModInt x) const {
    ModInt o = *this;
    o /= x;
    return o;
  }
  bool operator==(ModInt x) const { return value == x.value; }
  bool operator!=(ModInt x) const { return !(*this == x); }
  ModInt operator-() const { return ModInt(0) - *this; }
  ModInt operator^(long long x) const {
    ModInt ret = 1;
    ModInt mul = *this;
    while (x) {
      if (x & 1) ret *= mul;
      mul *= mul;
      x >>= 1;
    }
    return ret;
  }
  ModInt& operator^=(long long x) { return *this = *this ^ x; }

 private:
  void invert() { *this ^= MOD - 2; }

 public:
  void answer() { std::cout << value << std::endl; }
};
int main() {
  int n;
  readInteger(n);
  vector<int> a(n), b(n);
  for (int i = (0); i < int(n); i++) readInteger(a[i]);
  for (int i = (0); i < int(n); i++) readInteger(b[i]);
  a.erase(find(a.begin(), a.end(), 0));
  b.erase(find(b.begin(), b.end(), 0));
  n--;
  int idx = 0;
  while (b[idx] != a[0]) ++idx;
  for (int i = (0); i < int(n); i++) {
    if (a[i] != b[(idx + i) % n]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
}
