#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000007;
void solve() {
  int n;
  cin >> n;
  n--;
  vector<int> inp;
  vector<int> need;
  int zero_pos = 0;
  for (int i = 0; i < n + 1; ++i) {
    int tmp;
    cin >> tmp;
    if (tmp != 0) inp.push_back(tmp);
  }
  int start = 0;
  for (int i = 0; i < n + 1; ++i) {
    int tmp;
    cin >> tmp;
    if (tmp != 0) {
      need.push_back(tmp);
      if (tmp == inp[0]) start = need.size() - 1;
    }
  }
  int i = 0;
  int end = start;
  bool good = true;
  do {
    if (inp[i] != need[start]) {
      good = false;
      break;
    }
    start++;
    i++;
    if (i == n) i = 0;
    if (start == n) start = 0;
  } while (start != end);
  if (!good)
    cout << "NO";
  else
    cout << "YES";
}
int main() {
  ios::sync_with_stdio(false);
  solve();
}
