#include <bits/stdc++.h>
using namespace std;
long long n, x, c;
vector<long long> arr;
vector<long long> brr;
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  bool flag = 1;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    cin >> x;
    if (x == 0)
      continue;
    else {
      arr.push_back(x);
      mp[x] = c;
      c++;
    }
  }
  bool first = 0;
  long long ind;
  for (long long i = (long long)(1); i <= (long long)(n); i++) {
    cin >> x;
    if (x == 0) continue;
    if (!first) {
      ind = mp[x];
      first = 1;
    }
    if (arr[ind] != x) {
      flag = 0;
      break;
    }
    ind++;
    ind = ind % c;
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
