#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;
int arr[N], brr[N];
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int save;
  for (int i = 0; i < n; i++) {
    cin >> brr[i];
    if (brr[i] == 0) {
      save = i;
    }
  }
  int indx = 0;
  if (brr[0] == 0) indx = 1;
  for (int i = 0; i < n; i++) {
    if (arr[i] == brr[indx]) {
      ans.push_back(0);
      for (int j = i; j < n; j++)
        if (arr[j]) ans.push_back(arr[j]);
      for (int j = 0; j < i; j++)
        if (arr[j]) ans.push_back(arr[j]);
      break;
    }
  }
  for (int i = 0; i < save; i++) {
    swap(ans[i], ans[i + 1]);
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] != brr[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
