#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m, i, j = 0, p = 0, k = 0, flag = 0, ans;
  cin >> n;
  long int a[n], b[n];
  for (i = 0; i < n; i++) {
    cin >> m;
    if (m != 0) a[p++] = m;
  }
  for (i = 0; i < n; i++) {
    cin >> m;
    if (m != 0) b[k++] = m;
    if (m == a[0]) ans = k - 1;
  }
  for (i = 0; i < k - ans; i++) {
    if (a[i] != b[ans + i]) {
      cout << "NO";
      flag++;
      return 0;
    }
  }
  for (j = 0; j < ans; j++) {
    if (b[j] != a[j + i]) {
      cout << "NO";
      flag++;
      return 0;
    }
  }
  if (flag == 0) cout << "YES";
  return 0;
}
