#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 1000;
int n;
int a[MAXN], b[MAXN];
int a2[MAXN], b2[MAXN];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  int idx = find(a, a + n, 1) - a;
  int last_idx = 0;
  for (int i = idx; i < n; ++i) {
    if (a[i] == 0) continue;
    a2[last_idx++] = a[i];
  }
  for (int i = 0; i < idx; ++i) {
    if (a[i] == 0) continue;
    a2[last_idx++] = a[i];
  }
  idx = find(b, b + n, 1) - b;
  last_idx = 0;
  for (int i = idx; i < n; ++i) {
    if (b[i] == 0) continue;
    b2[last_idx++] = b[i];
  }
  for (int i = 0; i < idx; ++i) {
    if (b[i] == 0) continue;
    b2[last_idx++] = b[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    if (a2[i] != b2[i]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}
