#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string a = "", b = "", s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s != "0") a += s;
  }
  a = a + a;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s != "0") b += s;
  }
  if (a.find(b) != string::npos)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
