#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> have(n);
  for (int i = 0; i < n; i++) {
    cin >> have[i];
  }
  vector<int> want(n);
  for (int i = 0; i < n; i++) {
    cin >> want[i];
  }
  int pos = 0;
  int look = (want[0] == 0 ? want[1] : want[0]);
  for (int i = 0; i < n; i++) {
    if (have[i] == look) {
      pos = i;
      break;
    }
  }
  int off_w = 0, off_h = 0;
  if (look == want[1]) off_w = 1;
  for (int i = 0; i < n; i++) {
    int w = want[(i + off_w) % n];
    int h = have[(i + pos + off_h) % n];
    if (w != h) {
      if (w && h) {
        cout << "NO\n";
        return 0;
      }
      if (!h) {
        if (have[(i + pos + 1) % n] != w) {
          cout << "NO\n";
          return 0;
        }
        off_h++;
      } else if (!w) {
        if (want[(i + 1 + off_w) % n] != h) {
          cout << "NO\n";
          return 0;
        }
        off_w++;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
