#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  srand(time(0));
  int n;
  cin >> n;
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      a.push_back(x);
    }
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      b.push_back(x);
    }
  }
  for (int i = 0; i < n - 1; i++) {
    a.push_back(a[i]);
  }
  string ans = "NO";
  for (int i = 0; i < n; i++) {
    if (a[i] == b[0]) {
      bool done = 1;
      for (int j = 0; j < n - 1; j++) {
        if (b[j] != a[i + j]) {
          done = 0;
          break;
        }
      }
      if (done) {
        ans = "YES";
      }
      break;
    }
  }
  cout << ans;
  return 0;
}
