#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
  int n;
  cin >> n;
  int check = false;
  int t = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (!x)
      check = true;
    else {
      t++;
      a[x] = t;
    }
    v.push_back(x);
  }
  int r = -1;
  bool check2 = true;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      if (a[x] != r + 1 && r != -1 && !(a[x] == 1 && r == t)) {
        cout << "NO" << endl;
        return 0;
      } else
        r = a[x];
    }
    if (v[i] != x) check2 = false;
  }
  if (!check2 && !check) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}
