#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  string a, b, c;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c != "0") a += c;
  }
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c != "0") b += c;
  }
  a += a;
  if (strstr(a.c_str(), b.c_str()) == NULL)
    cout << "NO\n";
  else
    cout << "YES\n";
}
