#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline void set_bit(int &n, int b) { n |= (1ll << (b)); }
inline void unset_bit(int &n, int b) { n &= ~(1ll << (b)); }
inline void check(long long &x) {
  if (x >= MOD) x %= MOD;
}
const int MAXN = 2e5 + 5;
int pos[MAXN];
int ar[MAXN];
int fin[MAXN];
int main() {
  int n;
  cin >> n;
  vector<int> v, v2;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    if (ar[i] == 0) continue;
    ;
    v.push_back(ar[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &fin[i]);
    pos[fin[i]] = i;
  }
  int val = pos[v[0]];
  for (int i = val; i <= n; i++) {
    if (fin[i] == 0) continue;
    v2.push_back(fin[i]);
  }
  for (int i = 1; i < val; i++) {
    if (fin[i] == 0) continue;
    v2.push_back(fin[i]);
  }
  bool f = true;
  for (int i = 0; i < ((int)v.size()); i++) {
    if (v[i] != v2[i]) f = false;
  }
  if (f)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
