#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a, b, c, d;
int main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] != 0) c.push_back(a[i]);
  }
  for (int i = 0; i < n; i++)
    if (a[i] != 0) c.push_back(a[i]);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    if (b[i] != 0) d.push_back(b[i]);
  }
  for (int i = 0; i < n; i++)
    if (b[i] != 0) d.push_back(b[i]);
  bool b = false;
  int cnt = 1;
  int pos1 = 0, pos2 = 0;
  while (pos1 < 2 * n && pos2 < 2 * n) {
    if (c[pos1] == d[pos2]) {
      b = true;
      cnt++;
      pos1++, pos2++;
      if (cnt >= n - 1) {
        cout << "YES";
        return 0;
      }
    } else {
      if (b) {
        cout << "NO";
        return 0;
      } else
        pos2++;
    }
  }
}
