#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int a[MAXN];
int b[MAXN];
int tmp[MAXN];
int main() {
  int n;
  cin >> n;
  int aidx;
  for (int i = 0; i < n; i++) {
    cin >> tmp[i];
    if (tmp[i] == 0) aidx = i;
  }
  for (int i = 0; i < n; i++) a[i] = tmp[(i + aidx) % n];
  int bidx;
  for (int i = 0; i < n; i++) {
    cin >> tmp[i];
    if (tmp[i] == 0) bidx = i;
  }
  for (int i = 0; i < n; i++) b[i] = tmp[(i + bidx) % n];
  for (int i = 0; i < n - 1; i++) {
    a[i] = a[i + 1];
    b[i] = b[i + 1];
  }
  for (int i = 0; i < n - 1; i++)
    if (b[i] == a[0]) bidx = i;
  for (int i = 0; i < n - 1; i++)
    if (a[i] != b[(i + bidx) % (n - 1)]) {
      cout << "NO" << endl;
      return 0;
    }
  cout << "YES" << endl;
}
