#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, n, t;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> t;
    if (t != 0) a.push_back(t);
  }
  for (i = 0; i < n - 1; i++)
    if (a[i] != 0) a.push_back(a[i]);
  for (i = 0; i < n; i++) {
    cin >> t;
    if (t != 0) b.push_back(t);
  }
  for (i = 0; i < a.size(); i++) {
    if (a[i] == b[0]) {
      bool u = true;
      for (int j = i; j < i + n - 1; j++)
        if (a[j] != b[j - i]) u = false;
      if (u == false)
        cout << "NO";
      else
        cout << "YES";
      return 0;
    }
  }
  return 0;
}
