#include <bits/stdc++.h>
using namespace std;
const int nn = 200010;
int a[nn], b[nn], n, x;
int main() {
  ios::sync_with_stdio();
  cin.tie(0);
  cin >> n;
  int cnt = 0, pos;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0) continue;
    a[cnt++] = x;
  }
  cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0) continue;
    b[cnt++] = x;
    if (x == a[0]) pos = cnt - 1;
  }
  bool flag = true;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] != b[(i + pos) % (n - 1)]) flag = false;
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
  return 0;
}
