#include <bits/stdc++.h>
using namespace std;
string s1, s2;
bool check(string s1, string s2) {
  string s3 = s1 + s1;
  if (s3.find(s2) != std::string::npos) {
    return true;
  } else {
    return false;
  }
}
int main() {
  int n;
  cin >> n;
  int x;
  s1 = "";
  s2 = "";
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (x != 0) s1 += x + '0';
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (x != 0) s2 += x + '0';
  }
  if (check(s1, s2))
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
