#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 15;
const int Q = 1e9 + 7;
vector<int> v1, v2;
int a[M], b[M];
int main() {
  srand(time(NULL));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++)
    if (a[i] == 1) {
      for (int j = (i + 1) % n; j != i; j = (j + 1) % n)
        if (a[j]) v1.push_back(a[j]);
    }
  for (int i = 0; i < n; i++)
    if (b[i] == 1) {
      for (int j = (i + 1) % n; j != i; j = (j + 1) % n)
        if (b[j]) v2.push_back(b[j]);
    }
  for (int i = 0; i < (int)v1.size(); i++)
    if (v1[i] != v2[i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
