#include <bits/stdc++.h>
using namespace std;
int n, s, st, cnt, a[200005], b[200005];
int main() {
  int i, j, k;
  cin >> n;
  j = -1;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (j == -1 && a[i] != 0) j = st = i;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == a[j]) k = i;
  }
  while (1) {
    if (j == st) cnt++;
    if (cnt == 2) break;
    if (a[j] != b[k]) {
      cout << "NO";
      return 0;
    }
    while (1) {
      j = (j + 1) % n;
      if (a[j] != 0) break;
    }
    while (1) {
      k = (k + 1) % n;
      if (b[k] != 0) break;
    }
  }
  cout << "YES" << endl;
  return 0;
}
