#include <bits/stdc++.h>
using namespace std;
int a[200100], b[200100];
int main() {
  int n;
  cin >> n;
  int p1, p2;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) p1 = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] == 1) p2 = i;
  }
  bool ok = true;
  for (int i = 1; i <= n; i++) {
    if (a[p1] == 0) p1++;
    if (b[p2] == 0) p2++;
    if (p1 > n) p1 -= n;
    if (p2 > n) p2 -= n;
    if (a[p1] != b[p2]) {
      ok = false;
      break;
    }
    p1++;
    p2++;
    if (p1 > n) p1 -= n;
    if (p2 > n) p2 -= n;
  }
  if (ok)
    puts("YES");
  else
    puts("NO");
  return 0;
}
