#include <bits/stdc++.h>
using namespace std;
signed main() {
  int64_t n;
  cin >> n;
  vector<int64_t> cur, des;
  for (int64_t i = 0; i < n; i++) {
    int64_t temp;
    cin >> temp;
    if (temp != 0) cur.push_back(temp);
  }
  for (int64_t i = 0; i < n; i++) {
    int64_t temp;
    cin >> temp;
    if (temp != 0) des.push_back(temp);
  }
  if (n <= 3)
    cout << "YES";
  else {
    int64_t st = 2;
    int64_t st1;
    for (int64_t i = 0; i < (n - 1); i++) {
      if (cur[i] == des[st]) {
        st1 = i;
        break;
      }
    }
    int64_t cnt = 0;
    while (cnt < (n - 1)) {
      if (cur[st1] == des[st]) {
        st1 = (st1 + 1) % (n - 1);
        st = (st + 1) % (n - 1);
        cnt++;
      } else
        break;
    }
    if (cnt == (n - 1))
      cout << "YES";
    else
      cout << "NO";
  }
}
