#include <bits/stdc++.h>
using namespace std;
int a[444444];
int b[222222];
int main() {
  int n;
  scanf("%d", &n);
  int p0 = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 0) {
      p0 = i;
    }
  }
  rotate(a, a + p0, a + n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (b[i] == 0) {
      p0 = i;
    }
  }
  rotate(b, b + p0, b + n);
  int pp = -1;
  for (int i = 1; i < n; i++) {
    if (a[i] == b[1]) {
      pp = i;
      break;
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[pp] != b[i]) {
      cout << "NO";
      return 0;
    }
    pp++;
    if (pp >= n) {
      pp = 1;
    }
  }
  cout << "YES";
  return 0;
}
