#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  smain();
  return 0;
}
long long n, a[200002], b[200002];
void smain() {
  for (; cin >> n;) {
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++) cin >> b[i];
    long long i = 0;
    for (; a[i]; ++i)
      ;
    for (; i < n - 1; ++i) a[i] = a[i + 1];
    for (i = 0; b[i]; ++i)
      ;
    for (; i < n - 1; ++i) b[i] = b[i + 1];
    for (i = 0; i < n; ++i)
      if (a[0] == b[i]) break;
    rotate(b, b + i, b + n - 1);
    bool ok = true;
    for (long long j = 0; j < n - 1; j++)
      if (a[j] != b[j]) ok = false;
    cout << (ok ? "YES\n" : "NO\n");
  }
}
