#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5);
int n, cur_i = 0;
int a[N];
void find(int num) {
  for (int i = 0; i < n; ++i) {
    if (a[i] == num) {
      cur_i = i + 1;
      return;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int b, i_beg = 1;
  scanf("%d", &b);
  if (!b) {
    scanf("%d", &b);
    i_beg = 2;
  }
  find(b);
  for (int i = i_beg; i < n; ++i) {
    scanf("%d", &b);
    if (!b) {
      continue;
    }
    cur_i %= n;
    if (!a[cur_i]) {
      cur_i++;
      cur_i %= n;
    }
    if (a[cur_i] != b) {
      printf("NO");
      return 0;
    }
    cur_i++;
  }
  printf("YES");
  return 0;
}
