#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
vector<int> v, v1;
int n, p[MAXN], p1[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = (0); i < int(n); i++) scanf("%d", &p[i]);
  int start;
  for (int i = (0); i < int(n); i++)
    if (p[i] == 1) start = i;
  v.push_back(p[start]);
  start++;
  start %= n;
  while (p[start] != 1) {
    if (p[start] != 0) v.push_back(p[start]);
    start++;
    start %= n;
  }
  for (int i = (0); i < int(n); i++) scanf("%d", &p[i]);
  for (int i = (0); i < int(n); i++)
    if (p[i] == 1) start = i;
  v1.push_back(1);
  start++;
  start %= n;
  while (p[start] != 1) {
    if (p[start] != 0) v1.push_back(p[start]);
    start++;
    start %= n;
  }
  (v == v1) ? puts("YES") : puts("NO");
  return 0;
}
