#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  int a0, b0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 0) a0 = i;
    if (b[i] == 0) b0 = i;
  }
  a.erase(a.begin() + a0);
  b.erase(b.begin() + b0);
  int a1, b1;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] == 1) a1 = i;
    if (b[i] == 1) b1 = i;
  }
  for (int i = 0; i < (n - 1); ++i) {
    if (a[(a1 + i) % (n - 1)] != b[(b1 + i) % (n - 1)]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
