#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int a[N];
int b[N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", b + i);
  }
  int j = 0;
  while (b[j] == 0) {
    j++;
  }
  int i = 0;
  while (a[i] == 0 || a[i] != b[j]) {
    i++;
  }
  for (int x = 0; x < n; x++) {
    i = (i + 1) % n;
    if (a[i] == 0) {
      i = (i + 1) % n;
    }
    j = (j + 1) % n;
    if (b[j] == 0) {
      j = (j + 1) % n;
    }
    if (a[i] != b[j]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
