#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T a, T b) {
  T x;
  if (b == 0)
    x = 1;
  else
    x = a;
  for (size_t i = 1; i < b; i++) x *= a;
  return x;
}
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int n, m, a, b, c, ab, ba, x, y, z, avg, sum;
int arr2[400001], arr3[200001], arr4[200001], arr5[100001];
char c1, c2;
vector<pair<string, long long int> > vec;
vector<long long int> v, v2;
bool f, f1, f2;
string str, s1, s2, s3, s4;
map<long long int, long long int> mp, mp1;
set<int> seto;
double d, d1;
long long int x1, x2, y11, y2;
long long int mini = 1000000000, maxi = 0;
int main() {
  cin >> n;
  v.resize(n);
  v2.resize(n);
  for (long long int i = 0; i < n; i++) scanf("%lld", &v[i]);
  for (long long int i = 0; i < n; i++) scanf("%lld", &v2[i]);
  v.erase(min_element(v.begin(), v.end()));
  v2.erase(min_element(v2.begin(), v2.end()));
  x = 200000;
  for (long long int i = 0; i < n - 1; i++) {
    arr2[i + x] = v2[i];
  }
  while (v[0] != arr2[x]) {
    a = arr2[n + x - 2];
    arr2[--x] = a;
  }
  for (long long int i = 0; i < n - 1; i++)
    if (v[i] != arr2[x++]) {
      f = 1;
      break;
    }
  if (!f)
    cout << "YES";
  else
    cout << "NO";
}
