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