#include <bits/stdc++.h>
using namespace std;
const int maxn = 200110;
int a[maxn];
int b[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  string s1 = "";
  string s2 = "";
  int sa, sb;
  for (int i = 0; i < n; ++i) {
    if (a[i] == 1) sa = i;
    if (b[i] == 1) sb = i;
  }
  bool flag = true;
  for (int i = 0; i < n; ++i) {
    int lx = (sa + i) % n;
    int ly = (sb + i) % n;
    if (a[lx] != 0) s1 += (char)(a[lx] + '0');
    if (b[ly] != 0) s2 += (char)(b[ly] + '0');
  }
  printf("%s\n", s1 == s2 ? "YES" : "NO");
  return 0;
}
