#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 9;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 8;
long long n, m, a[maxn], b[maxn];
void solve() {
  long long i, j, pos = 1;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) cin >> b[i];
  if (a[1] == 0) swap(a[1], a[2]);
  for (pos = 1; pos <= n; pos++)
    if (b[pos] == a[1]) break;
  for (i = 2; i <= n; i++)
    if (a[i] != 0) {
      pos++;
      if (pos == n + 1) pos = 1;
      if (b[pos] == 0) pos++;
      if (pos == n + 1) pos = 1;
      if (b[pos] != a[i]) return (void)(cout << "NO" << endl);
    }
  cout << "YES" << endl;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
