#include <bits/stdc++.h>
using namespace std;
const int Max = 2e5 + 10;
int nexta[Max], nextb[Max], a[Max], b[Max];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i > 0) {
      nexta[a[i - 1]] = a[i];
    }
  }
  nexta[a[n - 1]] = a[0];
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    if (i > 0) {
      nextb[b[i - 1]] = b[i];
    }
  }
  nextb[b[n - 1]] = b[0];
  int f = 1;
  int k = a[0];
  while (nexta[k] != 0) {
    k = nexta[k];
  }
  int s1 = k;
  int s2 = s1;
  int i = nexta[s1];
  int j = nextb[s2];
  while (1) {
    if (i == 0) {
      if (i == s1) {
        break;
      }
      i = nexta[i];
    }
    if (j == 0) {
      if (j == s2) {
        break;
      }
      j = nextb[j];
    }
    if (i == j) {
      if (i == s1 || j == s2) {
        break;
      }
      i = nexta[i];
      j = nextb[j];
    } else {
      f = 0;
      break;
    }
    if (f == 0) {
      break;
    }
  }
  if (f) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
