#include <bits/stdc++.h>
using namespace std;
long long int a[200010], b[200010], c[200010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m1, m2;
  cin >> n;
  long long int i, j;
  m1 = 0;
  for (i = 0; i < n; i++) {
    cin >> j;
    if (j == 0)
      continue;
    else {
      a[m1] = j;
      m1++;
    }
  }
  m2 = 0;
  for (i = 0; i < n; i++) {
    cin >> j;
    if (j == 0)
      continue;
    else {
      b[m2] = j;
      m2++;
    }
  }
  bool flag = 0;
  long long int index;
  if (m1 == m2) {
    for (i = 0; i < m1; i++) {
      if (a[i] == b[0]) break;
    }
    index = i;
    flag = 1;
    j = 0;
    for (i = index;; i = (i + 1) % m1) {
      if (a[i] == b[j]) {
        j++;
      } else {
        flag = 0;
        break;
      }
      if (j == m1) break;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
