#include <bits/stdc++.h>
using namespace std;
int a[200000], b[200000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v, v2;
  int pos, pos2;
  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] != 0) v.push_back(a[i]);
    if (b[i] != 0) v2.push_back(b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) pos = i;
    if (v2[i] == 1) pos2 = i;
  }
  for (int i = 0; i < n; i++) {
    if (v[(i + pos) % (n - 1)] != v2[(i + pos2) % (n - 1)]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
