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