#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v1, v2;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a) v1.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a) v2.push_back(a);
  }
  for (int i = 0; i < n - 1; i++) {
    if (v1[0] == v2[i]) {
      rotate(v2.begin(), v2.begin() + i, v2.end());
      break;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (v1[i] != v2[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
