#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> statue1(n - 1);
  vector<int> statue2(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    int a;
    cin >> a;
    if (a > 0)
      statue1[i] = a;
    else
      --i;
  }
  for (int i = 0; i < n - 1; ++i) {
    int b;
    cin >> b;
    if (b > 0)
      statue2[i] = b;
    else
      --i;
  }
  vector<int>::iterator i = statue1.begin();
  vector<int>::iterator j = find(statue2.begin(), statue2.end(), *i);
  while (i != statue1.end()) {
    if (*i == *j) {
      ++i;
      ++j;
      if (j == statue2.end()) j = statue2.begin();
    } else {
      cout << "No";
      return 0;
    }
  }
  cout << "YES";
  return 0;
  return 0;
}
