#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v1, v2, v3, v4;
int main(void) {
  int i, j, zero;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    if (j != 0) v1.push_back(j);
  }
  v3 = v1;
  for (i = 0; i < v1.size(); i++) v3.push_back(v1[i]);
  for (i = 0; i < n; i++) {
    scanf("%d", &j);
    if (j != 0) v2.push_back(j);
  }
  int idx1 = -1, idx2 = -1;
  for (i = 0; i < v3.size(); i++) {
    if (v3[i] == v2[0]) {
      if (idx1 == -1)
        idx1 = i;
      else
        idx2 = i;
    }
  }
  int ans = 0, matches = 0;
  if (idx1 != -1) {
    j = 0;
    for (i = idx1; i < min(v3.size(), idx1 + v2.size()); i++) {
      if (v3[i] == v2[j++])
        matches++;
      else
        break;
    }
    if (matches == v2.size()) ans = 1;
  }
  if (idx2 != -1) {
    matches = 0;
    j = 0;
    for (i = idx2; i < min(v3.size(), idx1 + v2.size()); i++) {
      if (v3[i] == v2[j++])
        matches++;
      else
        break;
    }
    if (matches == v2.size()) ans = 1;
  }
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
