#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int block_size = 360;
const int maxn = 100010;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
template <typename T>
int sign(const T& a) {
  if (a < 0) {
    return -1;
  }
  if (a > 0) {
    return 1;
  }
  return 0;
}
long long cross_product(const complex<long long>& from, complex<long long> a,
                        complex<long long> b) {
  a -= from;
  b -= from;
  return a.imag() * b.real() - a.real() - b.imag();
}
string a = "", b = "";
int main() {
  int n;
  scanf("%d", &n);
  for (long long i = 0; i < n; i++) {
    string c;
    cin >> c;
    if (c != "0") {
      a += c;
    }
  }
  for (long long i = 0; i < n; i++) {
    string c;
    cin >> c;
    if (c != "0") {
      b += c;
    }
  }
  a = a + a;
  if (strstr(a.c_str(), b.c_str())) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
