#include <bits/stdc++.h>
using namespace std;
const int max_n = 2 * 1e5 + 2;
int n;
vector<int> a;
vector<int> b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp) a.push_back(tmp);
  }
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp) b.push_back(tmp);
  }
  if (a.size() == b.size()) {
    int aidx = 0;
    int bidx = -1;
    for (int i = 0; i < b.size(); i++)
      if (a[aidx] == b[i]) bidx = i;
    if (bidx == -1) {
      cout << "NO";
      return 0;
    }
    for (int i = 0; i < b.size(); i++)
      if (a[(aidx + i) % b.size()] != b[(bidx + i) % b.size()]) {
        cout << "NO";
        return 0;
      }
  } else {
    cout << "NO";
    return 0;
  }
  cout << "YES";
}
