#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0;
int a[200005], b[200005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x) a[cnt++] = x;
  }
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (x) b[cnt++] = x;
  }
  int now, fl = 0;
  for (int i = 0; i < n - 1; i++)
    if (a[0] == b[i]) now = i;
  for (int i = 1; i < n - 1; i++) {
    if (a[i] != b[(now + i) % (n - 1)]) fl = 1;
  }
  if (fl)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
