#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int a[N];
int b[N];
int posa[N];
int posb[N];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> temp, temp1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != 0) {
      temp.push_back(a[i]);
    }
    if (b[i] != 0) {
      temp1.push_back(b[i]);
    }
  }
  for (int i = 0; i < temp.size(); i++) {
    posa[temp[i]] = i;
    posb[temp1[i]] = i;
  }
  int diff = 0;
  for (int i = 1; i < n; i++) {
    if (posb[i] >= posa[i]) {
      diff = posb[i] - posa[i];
      break;
    }
  }
  bool ok = true;
  for (int i = 0; i < temp.size(); i++) {
    if (temp1[((i + diff) % (n - 1))] != temp[i]) {
      ok = false;
      break;
    }
  }
  if ((ok))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
