#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, d[1011000], j, k, n, m, timer = 0, l, r, x, y;
int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (j = 0; j < n; j++) {
    cin >> d[j];
  }
  j = 0;
  fl = 0;
  for (i = 0; i < n; i++) {
    x = 0;
    if (c[i] == 0) continue;
    while (fl < n) {
      if (d[j] == c[i]) {
        j++;
        j %= n;
        fl++;
        x = 1;
        break;
      }
      j++;
      j %= n;
      fl++;
    }
    if (x == 0) {
      cout << "NO\n";
      return 0;
    }
    if (i == 0 || (c[0] == 0 && i == 1)) fl = 1;
  }
  cout << "YES\n";
  return 0;
}
