#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, i, j, x, y, p, q;
  bool f = true;
  cin >> n;
  int a[n + 1], b[n + 1], c[n + 1];
  for (i = 1; i <= n; i++) cin >> a[i];
  ;
  for (i = 1; i <= n; i++) cin >> b[i];
  ;
  x = 1;
  if (b[1] == 0) x = 2;
  for (i = 1; i <= n; i++) {
    if (a[i] == b[x]) break;
  }
  for (j = 1; j <= n; j++) {
    if (b[j] == 0) continue;
    if (a[i] == 0) {
      i++;
      j--;
      continue;
    }
    if (b[j] != a[i]) {
      f = false;
      break;
    } else {
      i++;
      if (i > n) i = i % n;
    }
  }
  if (f)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
