#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B[i];
  vector<int> A1, B1;
  for (int i = 0; i < N; i++)
    if (A[i] == 1)
      for (int j = i; j < N + i; j++)
        if (A[j % N] != 0) A1.push_back(A[j % N]);
  for (int i = 0; i < N; i++)
    if (B[i] == 1)
      for (int j = i; j < N + i; j++)
        if (B[j % N] != 0) B1.push_back(B[j % N]);
  if (A1 != B1)
    cout << "NO\n";
  else
    cout << "YES\n";
  return 0;
}
