#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int n;
vector<int> red;
int arr[MAXN];
int wanted[MAXN];
int inc(int x) {
  int ret = x + 1;
  if (ret == n) return 0;
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  int startNum = arr[0];
  if (startNum == 0) startNum = arr[1];
  int startPos;
  for (int i = 0; i < n; i++) {
    scanf("%d", &wanted[i]);
    if (wanted[i] == startNum) startPos = i;
  }
  int j = 0;
  bool ok = 1;
  for (int i = startPos;;) {
    if (arr[j] == 0) j = inc(j);
    if (wanted[i] != arr[j]) {
      ok = 0;
      break;
    }
    i = inc(i);
    j = inc(j);
    if (wanted[i] == 0) i = inc(i);
    if (i == startPos) break;
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
