#include <bits/stdc++.h>
using namespace std;
int a[200001];
int b[200001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int endI;
  int start = a[0];
  int startI = 0;
  if (a[0] == 0) {
    start = a[1];
    startI = 1;
  }
  for (int i = 0; i < n; i++) {
    if (b[i] == start) endI = i;
  }
  bool possible = true;
  for (int r = 0; r < n; r++) {
    if (a[startI] == 0) startI++;
    if (b[endI] == 0) endI++;
    if (startI >= n) {
      startI = 0;
    }
    if (endI >= n) {
      endI = 0;
    }
    if (a[startI] == 0) startI++;
    if (b[endI] == 0) endI++;
    if (a[startI] != b[endI]) {
      possible = false;
      break;
    }
    startI++;
    endI++;
  }
  if (possible)
    cout << "YES";
  else
    cout << "NO";
}
