#include <bits/stdc++.h>
using namespace std;
int next1[200001];
int next2[200001];
int a[200001];
int b[200001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) next1[a[i]] = a[(i + 1) % n];
  for (int i = 0; i < n; i++) next2[b[i]] = b[(i + 1) % n];
  for (int i = 0; i < n; i++) {
    if (next1[i] == 0) next1[i] = next1[0];
    if (next2[i] == 0) next2[i] = next2[0];
  }
  for (int i = 1; i < n; i++) {
    if (next1[i] != next2[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
