#include <bits/stdc++.h>
using namespace std;
int n;
const int MAXN = 222222;
vector<int> A, B;
void load() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (a) A.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (a) B.push_back(a);
  }
}
bool solve() {
  int a = A.size(), b = B.size();
  if (a != b) return false;
  if (a == n) return false;
  int k = -1;
  for (int i = 0; i < b; i++) {
    if (B[i] == A[0]) k = i;
  }
  if (k == -1) return false;
  for (int i = 0; i < a; i++) {
    if (B[(k + i) % a] != A[i]) return false;
  }
  return true;
}
int main() {
  load();
  if (solve())
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
