#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
int N, A[maxN], B[maxN], C[maxN], D[maxN];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++)
    if (A[i] == 1) {
      int vt = i;
      for (int j = 0; j < N; j++) C[j] = A[vt], vt = (vt + 1) % N;
      break;
    }
  for (int i = 0; i < N; i++)
    if (B[i] == 1) {
      int vt = i;
      for (int j = 0; j < N; j++) D[j] = B[vt], vt = (vt + 1) % N;
      break;
    }
  int vtc = 0, vtd = 0;
  for (int i = 0; i < N; i++) {
    if (C[i] == 0) vtc = i;
    if (D[i] == 0) vtd = i;
  }
  while (vtc < vtd) swap(C[vtc], C[vtc + 1]), vtc++;
  while (vtd < vtc) swap(D[vtd], D[vtd + 1]), vtd++;
  bool flag = 1;
  for (int i = 0; i < N; i++)
    if (C[i] != D[i]) flag = 0;
  puts(flag ? "YES" : "NO");
}
