#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mof = 1000000007;
const int inf = 1000000010;
const long long llinf = 1000000007000000007;
const double pi = 3.14159265359;
int a[211111];
int b[211111];
int A[211111];
int B[211111];
int main() {
  int n;
  cin >> n;
  int sz = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x != 0) {
      a[sz] = x;
      sz++;
    }
  }
  sz = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x != 0) {
      b[sz] = x;
      sz++;
    }
  }
  int first = a[0];
  int ind = 0;
  for (int i = 0; i < n - 1; i++) {
    if (b[i] == first) {
      ind = i;
      break;
    }
  }
  bool ok = true;
  for (int i = 0; i < n - 1; i++) {
    if (b[(i + ind) % (n - 1)] != a[i]) {
      ok = false;
    }
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
