#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> order, order1;
  int e = 0, e1 = 0;
  for (int i = 0; i < n; i++) {
    int tem;
    scanf("%d", &tem);
    if (tem == 0)
      e++;
    else
      order.push_back(tem);
  }
  for (int i = 0; i < n; i++) {
    int tem;
    scanf("%d", &tem);
    if (tem == 0)
      e1++;
    else
      order1.push_back(tem);
  }
  if (e != e1) {
    cout << "NO" << endl;
    return 0;
  };
  if (e == n) {
    cout << "YES" << endl;
    return 0;
  };
  int ind = -1;
  for (int i = 0; i < order1.size(); i++)
    if (order1[i] == order[0]) {
      ind = i;
      break;
    }
  if (ind == -1) {
    cout << "NO" << endl;
    return 0;
  };
  for (int i = 0; i < order1.size(); i++, ind++) {
    if (ind == order.size()) ind = 0;
    if (order1[ind] != order[i]) {
      cout << "NO" << endl;
      return 0;
    };
  }
  {
    cout << "YES" << endl;
    return 0;
  };
}
