#include <bits/stdc++.h>
using namespace std;
int n, a[400010], b[400010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++)
    if (a[i] == 0) {
      for (int j = i; j < n; j++) a[j] = a[j + 1];
      break;
    }
  for (int i = 1; i <= n; i++)
    if (b[i] == 0) {
      for (int j = i; j < n; j++) b[j] = b[j + 1];
      break;
    }
  n--;
  int falg = 0;
  for (int i = 1; i <= n; i++) b[i + n] = b[i];
  for (int i = 1; i <= n; i++)
    if (b[i] == a[1]) {
      for (int j = 1; j <= n; j++)
        if (b[i + j - 1] == a[j])
          continue;
        else
          falg = 1;
      break;
    }
  if (falg == 0)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
