#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
const int N = 2e5 + 10;
const int MOD = 1e9 + 7;
const long double eps = 1e-12;
int a[N], b[N], c, k;
int main() {
  int n = in();
  for (int i = 0; i < n; i++) a[i] = in(), k = (a[i] == 1) ? i : k;
  for (int i = 0; i < n; i++) b[i] = in(), c = (b[i] == 1) ? i : c;
  vector<int> v1, v2;
  for (int i = k; i < n; i++)
    if (a[i] != 0) v1.push_back(a[i]);
  for (int i = 0; i < k; i++)
    if (a[i] != 0) v1.push_back(a[i]);
  for (int i = c; i < n; i++)
    if (b[i] != 0) v2.push_back(b[i]);
  for (int i = 0; i < c; i++)
    if (b[i] != 0) v2.push_back(b[i]);
  for (int i = 0; i < n - 1; i++)
    if (v1[i] != v2[i]) return cout << "NO", 0;
  cout << "YES";
  return 0;
}
