#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
int a[N], n, m, x, y, z, s, s2, t1, t2, g[N], g2[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != 0) {
      g[++s] = a[i];
      if (a[i] == 1) t1 = s;
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] != 0) {
      g2[++s2] = a[i];
      if (a[i] == 1) t2 = s2;
    }
  }
  while (1) {
    t1++;
    t2++;
    if (t1 > s) t1 = 1;
    if (t2 > s2) t2 = 1;
    if (g[t1] != g2[t2]) {
      cout << "NO\n";
      return 0;
    }
    if (g[t1] == 1) {
      cout << "YES\n";
      return 0;
    }
  }
  return 0;
}
