#include <bits/stdc++.h>
using namespace std;
int a[200020], b[200020], n;
int cnt1, cnt2, cnt, cur, dd;
int main() {
  scanf("%d", &n);
  cnt = n - 1;
  cnt1 = 0;
  cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &cur);
    if (cur) a[cnt1++] = cur;
  }
  for (int j = 1; j <= n; j++) {
    scanf("%d", &cur);
    if (cur) b[cnt2++] = cur;
    if (cur == a[0]) dd = cnt2 - 1;
  }
  for (int i = 0; i < cnt; i++) {
    if (a[i] != b[(i + dd) % cnt]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}
