#include <bits/stdc++.h>
using namespace std;
long long n, i, x, k;
vector<long long> a;
vector<long long> b;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x != 0) a.push_back(x);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    if (x != 0) b.push_back(x);
  }
  for (i = 0; i < n; i++) {
    if (b[i] == a[0]) {
      k = i;
    }
  }
  n--;
  for (i = 0; i < n - k; i++) {
    if (a[i] != b[i + k]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (i = 0; i < k; i++) {
    if (b[i] != a[n - k + i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
