#include <bits/stdc++.h>
using namespace std;
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x > y ? y : x; }
int a[200000 + 20];
int b[200000 + 20];
int dp1[200000 + 20];
int dp2[200000 + 20];
int n;
int getlen1() {
  int i;
  int len = 1;
  dp1[len] = a[1];
  int j;
  int begin, end, pos;
  for (i = 2; i <= n - 1; i++) {
    if (a[i] > dp1[len]) {
      dp1[++len] = a[i];
    } else {
      begin = 1, end = len;
      while (begin <= end) {
        int mid = (begin + end) / 2;
        if (a[i] > dp1[mid]) {
          begin = mid + 1;
        } else
          end = mid - 1;
      }
      dp1[begin] = a[i];
    }
  }
  return len;
}
int getlen2() {
  int i;
  int len = 1;
  dp2[len] = b[1];
  int j;
  int begin, end, pos;
  for (i = 2; i <= n - 1; i++) {
    if (b[i] > dp2[len]) {
      dp2[++len] = b[i];
    } else {
      begin = 1, end = len;
      while (begin <= end) {
        int mid = (begin + end) / 2;
        if (b[i] > dp2[mid]) {
          begin = mid + 1;
        } else
          end = mid - 1;
      }
      dp2[begin] = b[i];
    }
  }
  return len;
}
void work() {
  scanf("%d", &n);
  int i;
  int u;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == 0) {
      u = i;
      break;
    }
  }
  for (i = u; i <= n; i++) {
    a[i] = a[i + 1];
  }
  for (i = 1; i <= n; i++) {
    if (b[i] == 0) {
      u = i;
      break;
    }
  }
  for (i = u; i <= n; i++) {
    b[i] = b[i + 1];
  }
  if (n <= 3) {
    printf("YES\n");
    return;
  }
  for (i = 1; i <= n - 1; i++) {
    if (b[1] == a[i]) {
      u = i;
      break;
    }
  }
  int time = 1;
  int b_len = 1;
  for (i = u; time <= n - 1; i++, time++, b_len++) {
    if (a[i] != b[b_len]) {
      printf("NO\n");
      return;
    }
    if (i == n - 1) i = 0;
  }
  printf("YES\n");
  return;
}
int main() {
  work();
  return 0;
}
