#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
template <class T>
T power(T a, T b) {
  T result = 1;
  while (b > 0) {
    if (b & 1) result = result * a;
    a = a * a;
    b >>= 1;
  }
  return result;
}
template <class T>
T powerMod(T a, T b, T c) {
  T result = 1 % c;
  while (b > 0) {
    if (b & 1) result = (result * a) % c;
    a = (a * a) % c;
    b >>= 1;
  }
  return result;
}
int A[200100], B[200100];
void eval() {
  int n, i, j, a, pos = 0;
  cin >> n;
  for (i = 0, j = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
    } else {
      A[j] = a;
      j++;
    }
  }
  for (i = 0, j = 0; i < n; i++) {
    cin >> a;
    if (a == 0) {
    } else {
      B[j] = a;
      j++;
    }
  }
  for (i = 0; i < n - 1; i++) {
    if (A[i] == B[0]) {
      pos = i;
    }
  }
  for (i = pos, j = 0; j < n - 1; j++) {
    if (A[i] != B[j]) {
      cout << "NO\n";
      return;
    }
    i = (i + 1) % (n - 1);
  }
  cout << "YES\n";
}
int main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  eval();
  return 0;
}
