#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> as(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &as[i]);
  }
  vector<int> bs(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &bs[i]);
  }
  int ptr1 = 0;
  for (int i = 0; i < n; i++) {
    if (as[i] == 0) {
      ptr1 = i;
      break;
    }
  }
  ptr1 = (ptr1 + 1) % n;
  int ptr2 = 0;
  for (int i = 0; i < n; i++) {
    if (bs[i] == as[ptr1]) {
      ptr2 = i;
      break;
    }
  }
  bool possible = true;
  while (as[ptr1] != 0) {
    if (bs[ptr2] == 0) {
      ptr2 = (ptr2 + 1) % n;
    }
    if (as[ptr1] != bs[ptr2]) {
      possible = false;
      break;
    }
    ptr1 = (ptr1 + 1) % n;
    ptr2 = (ptr2 + 1) % n;
  }
  if (possible) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
