#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
vector<int> v1, v2;
int main() {
  int n, f1 = 0, f2 = 0, pos = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1) f1 = i;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 1) f2 = i;
  }
  pos = f1;
  for (int i = 0; i < n; i++) {
    if (a[pos] != 0) v1.push_back(a[pos]);
    pos = (pos + 1) % n;
  }
  pos = f2;
  for (int i = 0; i < n; i++) {
    if (b[pos] != 0) v2.push_back(b[pos]);
    pos = (pos + 1) % n;
  }
  for (int i = 0; i < n - 1; i++) {
    if (v1[i] != v2[i]) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
