#include <bits/stdc++.h>
using namespace std;
long a[200001];
long b[200001];
long n;
int main() {
  cin >> n;
  int k = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[k];
    if (a[k] != 0) k++;
  }
  k = 1;
  for (int i = 1; i <= n; i++) {
    cin >> b[k];
    if (b[k] != 0) k++;
  }
  long j = 1;
  while (b[1] != a[j]) {
    j++;
  }
  for (int i = 2; i <= n - 1; i++) {
    j++;
    if (j == n) j = 1;
    if (b[i] != a[j]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
