#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 2;
int a[N], b[N], o, n;
int main() {
  scanf("%d", &n);
  int m = n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) {
      i--;
      n--;
    };
  }
  n++;
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 0) {
      i--;
      m--;
    }
    if (b[i] == a[0]) o = i;
  }
  for (int i = 0; i < m; i++) {
    if (a[i] != b[(i + o) % m]) {
      cout << "NO\n";
      return 0;
    }
  }
  printf("YES\n");
}
