#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, arr1[200010], arr2[200010];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr1[i]);
  for (int i = 0; i < n; i++) scanf("%d", &arr2[i]);
  int x = 0, y = 0;
  if (arr1[x] == 0) {
    x++;
  }
  while (arr2[y] != arr1[x]) y++;
  int cnt = 0;
  int fl = 0;
  while (cnt < n - 1) {
    if (arr1[x] == 0)
      x++;
    else if (arr2[y] == 0)
      y++;
    else if (arr1[x] != arr2[y]) {
      fl = 1;
      break;
    } else {
      x = (x + 1) % n;
      y = (y + 1) % n;
      cnt++;
    }
    x %= n;
    y %= n;
  }
  if (fl)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
