#include <bits/stdc++.h>
using namespace std;
const int MXN = 2e5 + 123;
const int TMXN = 1e5 * 8 + 1;
const long long INF = pow(2, 64);
const long long INFL = 1e18;
int n, q;
int a[MXN];
int b[MXN];
int inf[MXN], inf1[MXN];
vector<int> v, v1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i]) {
      v.push_back(a[i]);
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    if (b[i]) {
      v1.push_back(b[i]);
    }
  }
  inf[v[0]] = v[v.size() - 1];
  for (int i = 1; i < v.size(); i++) {
    inf[v[i]] = v[i - 1];
  }
  inf1[v1[0]] = v1[v1.size() - 1];
  for (int i = 1; i < v1.size(); i++) {
    inf1[v1[i]] = v1[i - 1];
  }
  for (int i = 1; i <= n - 1; i++) {
    if (inf[i] != inf1[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
