#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(2 * N), FA(N);
  int p0 = 0;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    if (x != 0) {
      FA[x] = p0;
      A[p0++] = x;
    }
  }
  vector<int> B(2 * N), FB(N);
  int p1 = 0;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    if (x != 0) {
      FB[x] = p1;
      B[p1++] = x;
    }
  }
  for (int i = 0; i < p1; ++i) {
    if (A[(FA[1] + i) % p1] != B[(FB[1] + i) % p1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
