#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e16;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int mod = int(1e9) + 7;
int n, a[1000100], x, p[1000100], m;
vector<int> v;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (x != 0) v.push_back(x);
  }
  v.push_back(-1);
  for (int i = 1; i <= n; i++)
    if (a[i] != 0) v.push_back(a[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] != 0) v.push_back(a[i]);
  m = v.size();
  for (int i = 1; i < m; i++) {
    int j = p[i - 1];
    while (j > 0 && v[i] != v[j]) j = p[j - 1];
    if (v[i] == v[j]) j++;
    p[i] = j;
    if (p[i] >= n - 1) {
      printf("YES");
      return 0;
    }
  }
  printf("NO");
  return 0;
}
