#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  bool hasZero = false;
  int n = 0;
  cin >> n;
  int *a = new int[n];
  int *b = new int[n];
  int aL = n;
  int bL = n;
  int ac = 0;
  for (int i = 0; i < n; i++) {
    int k = 0;
    cin >> k;
    if (k == 0) {
      hasZero = true;
      aL--;
    } else {
      a[ac] = k;
      ac++;
    }
  }
  bL = aL;
  int *c = new int[2 * aL];
  for (int i = 0; i < aL; i++) {
    c[i] = c[i + aL] = a[i];
  }
  ac = 0;
  for (int i = 0; i < n; i++) {
    int k = 0;
    cin >> k;
    if (k == 0) {
    } else {
      b[ac] = k;
      ac++;
    }
  }
  if (hasZero) {
    bool can = false;
    for (int i = 0; i < 2 * aL; i++) {
      if (can) {
        break;
      }
      for (int j = 0; j < aL; j++) {
        if (c[i + j] == b[j]) {
          if (j == bL - 1) {
            can = true;
          }
          continue;
        } else {
          break;
        }
      }
    }
    cout << (can ? "YES" : "NO") << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
