#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> start(n);
  vector<long long> goal(n);
  long long i;
  for (i = 0; i < n; i++) {
    cin >> start[i];
  }
  for (i = 0; i < n; i++) {
    cin >> goal[i];
  }
  vector<long long>::iterator it = find(start.begin(), start.end(), 0);
  start.erase(it);
  it = find(goal.begin(), goal.end(), 0);
  goal.erase(it);
  it = find(goal.begin(), goal.end(), start[0]);
  bool ok = true;
  i = it - goal.begin();
  int j;
  for (j = 0; (i + j) < (n - 1); j++) {
    if (start[j] != goal[i + j]) {
      ok = false;
      break;
    }
  }
  if (ok) {
    for (i = 0; j < (n - 1); j++, i++) {
      if (start[j] != goal[i]) {
        ok = false;
        break;
      }
    }
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  int xx;
  cin >> xx;
  return 0;
}
