#include <bits/stdc++.h>
using namespace std;
long long flag, cnt, j, i, k, powe, count1, count2;
long long int n, a, b, c, x, y, m, ans;
long long maxy, miny, sum, ann[1000010];
string s, s2;
long long mod = 1000000007;
int main() {
  cin >> n;
  n--;
  long long arr1[n], arr2[n];
  for (i = 0; i < n; i++) {
    cin >> arr1[i];
    if (arr1[i] == 0) i--;
  }
  for (i = 0; i < n; i++) {
    cin >> arr2[i];
    if (arr2[i] == 0) i--;
  }
  for (i = 0; i < n; i++) {
    if (arr2[i] == arr1[0]) break;
  }
  for (j = 0; j < n; j++) {
    if (arr1[j] != arr2[(i + j) % n]) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "No";
  else
    cout << "Yes";
}
