#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N];
int main() {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == 0) continue;
    a[cnt++] = x;
  }
  cnt = 0;
  int st;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == 0) continue;
    b[cnt++] = x;
    if (x == a[0]) st = cnt - 1;
  }
  bool flag = 1;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] != b[(i + st) % (n - 1)]) flag = 0;
  }
  puts(flag ? "YES" : "NO");
}
