#include <bits/stdc++.h>
using namespace std;
template <class c1>
ostream &_out(ostream &ost, c1 a, c1 b);
template <class T1, class T2>
ostream &operator<<(ostream &ost, pair<T1, T2> _cnt);
template <class T1>
ostream &operator<<(ostream &ost, vector<T1> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1>
ostream &operator<<(ostream &ost, deque<T1> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1>
ostream &operator<<(ostream &ost, queue<T1> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1>
ostream &operator<<(ostream &ost, list<T1> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1, class T2>
ostream &operator<<(ostream &ost, set<T1, T2> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &ost, map<T1, T2, T3> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1, class T2>
ostream &operator<<(ostream &ost, multiset<T1, T2> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &ost, multimap<T1, T2, T3> _cnt) {
  return _out(ost, _cnt.begin(), _cnt.end());
}
template <class T1, class T2>
ostream &operator<<(ostream &ost, pair<T1, T2> _cnt) {
  return ost << '(' << _cnt.first << ", " << _cnt.second << ')';
}
template <class T1>
ostream &_out(ostream &ost, T1 a, T1 b) {
  ost << '{';
  if (a != b) {
    ost << *a;
    while (++a != b) ost << ' ' << *a;
  }
  return ost << '}';
}
template <class Type, unsigned N, unsigned Last>
struct tuple_printer {
  static void print(std::ostream &out, const Type &value) {
    out << std::get<N>(value) << ", ";
    tuple_printer<Type, N + 1, Last>::print(out, value);
  }
};
template <class Type, unsigned N>
struct tuple_printer<Type, N, N> {
  static void print(std::ostream &out, const Type &value) {
    out << std::get<N>(value);
  }
};
template <class... Types>
std::ostream &operator<<(std::ostream &out, const std::tuple<Types...> &value) {
  out << '(';
  tuple_printer<std::tuple<Types...>, 0, sizeof...(Types) - 1>::print(out,
                                                                      value);
  out << ')';
  return out;
}
vector<string> _split(const string &s, char c) {
  int br = 0;
  vector<string> v(1);
  for (int i = 0; i < (((int)(s).size())); ++i) {
    if (s[i] == '[' || s[i] == '(' || s[i] == '{' || s[i] == '<')
      br++;
    else if (s[i] == ']' || s[i] == ')' || s[i] == '}' || s[i] == '>')
      br--;
    if (s[i] == c && br == 0)
      v.push_back("");
    else
      v.back().push_back(s[i]);
  }
  return move(v);
}
void _erre(vector<string>::iterator it) { (void)it; }
template <class T, class... Args>
void _erre(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n';
  _erre(++it, args...);
}
void _err(vector<string>::iterator it) {
  (void)it;
  cerr << '\n';
}
template <class T, class... Args>
void _err(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  _err(++it, args...);
}
template <class T>
T maxx(T g) {
  return g;
}
template <class T, class... Args>
T maxx(T a, Args... args) {
  return max(a, maxx(args...));
}
template <class T>
T minn(T g) {
  return g;
}
template <class T, class... Args>
T minn(T a, Args... args) {
  return min(a, minn(args...));
}
int t1[400010], t2[400010];
vector<int> v1, v2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int bg1 = -1, bg2 = -1;
  for (int i = 0; i < (n); ++i) {
    cin >> t1[i];
    if (t1[i] == 1) bg1 = i;
    t1[n + i] = t1[i];
  }
  for (int i = 0; i < (n); ++i) {
    cin >> t2[i];
    if (t2[i] == 1) bg2 = i;
    t2[n + i] = t2[i];
  }
  do {
    if (t1[bg1] != 0) v1.push_back(t1[bg1]);
    bg1++;
  } while (t1[bg1] != 1);
  do {
    if (t2[bg2] != 0) v2.push_back(t2[bg2]);
    bg2++;
  } while (t2[bg2] != 1);
  if (v1 == v2)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}
