#include <bits/stdc++.h>
using namespace std;
int n, m, k, dem, kq;
int a[200100];
int b[200100];
void solve() {
  int thuong;
  for (int i = 0; i < n; i++) {
    if (b[i] == a[0]) {
      thuong = i;
      break;
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i] != b[(i + thuong) % n]) {
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
}
int main() {
  int i, j;
  int cokq = 0;
  int x;
  while (scanf("%d", &n) == 1) {
    dem = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      if (x == 0) {
        cokq = 1;
      } else {
        a[dem++] = x;
      }
    }
    dem = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      if (x != 0) {
        b[dem++] = x;
      }
    }
    n = dem;
    if (cokq == 0) {
      printf("NO\n");
      continue;
    }
    solve();
  }
  return 0;
}
