#include <bits/stdc++.h>
using namespace std;
const int maxn = 200002;
int a[maxn], b[maxn], second, t, n;
vector<int> x, y;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) second = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] == 1) t = i;
  }
  for (int i = second; i < second + n; i++)
    if (a[i % n]) x.push_back(a[i % n]);
  for (int i = t; i < t + n; i++)
    if (b[i % n]) y.push_back(b[i % n]);
  for (int i = 0; i < n - 1; i++)
    if (x[i] != y[i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
