#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
long long MOD = 1000000009;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(n);
  long long int i1, i2;
  string s1, s2;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0)
      i1 = i;
    else
      s1 += (a[i] + '0');
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 0)
      i2 = i;
    else
      s2 += (b[i] + '0');
  }
  s1 += s1;
  if (s1.find(s2) != -1)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
}
