#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N], b[N], c[N], d[N];
int main() {
  int n;
  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 m = 0;
  for (int i = 0; i < n; i++)
    if (a[i] == 1)
      for (int j = 0; j < n; j++)
        if (a[(i + j) % n]) c[m++] = a[(i + j) % n];
  m = 0;
  for (int i = 0; i < n; i++)
    if (b[i] == 1)
      for (int j = 0; j < n; j++)
        if (b[(i + j) % n]) d[m++] = b[(i + j) % n];
  for (int i = 0; i < m; i++)
    if (c[i] != d[i]) {
      puts("NO");
      return 0;
    }
  puts("YES");
  return 0;
}
