#include <bits/stdc++.h>
using namespace std;
class HASH {
  int mod, base;
  vector<int> p = {1}, hashes = {0};
  int mul(int a, int b) { return a * 1ll * b % mod; }
  int add(int a, int b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
  }

 public:
  HASH(int _mod, int _base) : mod(_mod), base(_base) {}
  void push_back(int x) {
    hashes.push_back(add(mul(hashes.back(), base), x));
    p.push_back(mul(p.back(), base));
  }
  int get(int l, int r) {
    assert(r + 1 < hashes.size());
    return add(hashes[r + 1], -mul(p[r - l + 1], hashes[l]));
  }
};
struct D_HASH {
  const int B1 = 256;
  const int B2 = 128;
  const int M1 = 1e9 + 7;
  const int M2 = 1e9 + 33;
  array<HASH, 2> h;
  D_HASH() : h{HASH(M1, B1), HASH(M2, B2)} {}
  D_HASH(vector<int> str) : h{HASH(M1, B1), HASH(M2, B2)} {
    for (char c : str) {
      push_back(c);
    }
  }
  void push_back(int x) {
    h[0].push_back(x);
    h[1].push_back(x);
  }
  array<int, 2> get(int l, int r) {
    assert(l <= r);
    return {h[0].get(l, r), h[1].get(l, r)};
  };
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> A, B;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) A.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) B.push_back(x);
  }
  n--;
  for (int i = 0; i < n; i++) B.push_back(B[i]);
  D_HASH AH(A), BH(B);
  for (int i = 0; i < n; i++) {
    if (BH.get(i, i + n - 1) == AH.get(0, n - 1)) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
}
