#include <bits/stdc++.h>
using namespace std;
int arr[400010];
int arr2[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) i--, n--;
  }
  for (int i = n; i < 2 * n; i++) arr[i] = arr[i % n];
  n++;
  for (int i = 0; i < n; i++) {
    cin >> arr2[i];
    if (arr2[i] == 0) i--, n--;
  }
  int k;
  for (int i = 0; i < n; i++) {
    k = 0;
    while (k < n && i < 2 * n) {
      if (arr[i] == arr2[k])
        k++, i++;
      else
        break;
    }
    if (k > 1) i--;
    if (k == n) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
