#include <bits/stdc++.h>
using namespace std;
const int MAX_LEN = 200010;
int s0[MAX_LEN];
int sx[MAX_LEN];
int sk[MAX_LEN];
bool work(const int s0[], const int sx[], const int n) {
  int b_elem_i, b_elem;
  for (int i = 0; i < n; ++i)
    if (s0[i] == 0) {
      b_elem_i = (i + 1) % n;
      b_elem = s0[b_elem_i];
      break;
    }
  int b_elem_j, z_x;
  for (int i = 0; i < n; ++i)
    if (sx[i] == b_elem)
      b_elem_j = i;
    else if (sx[i] == 0)
      z_x = i;
  for (int i = 0; i < n; ++i) sk[(b_elem_j + i) % n] = s0[(b_elem_i + i) % n];
  int z_j;
  int dir;
  z_j = (b_elem_j == 0 ? n - 1 : b_elem_j - 1);
  dir = 1;
  while (z_j != z_x) {
    int next = (z_j + dir) % n;
    if (next < 0) next = n - 1;
    if (next == b_elem_j) {
      dir = -1 * dir;
    } else {
      swap(sk[z_j], sk[next]);
      z_j = next;
    }
  }
  for (int i = 0; i < n; ++i)
    if (sk[i] != sx[i]) return false;
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s0[i];
  for (int i = 0; i < n; ++i) cin >> sx[i];
  if (work(s0, sx, n))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
