#include <bits/stdc++.h>
using namespace std;
class point {
 public:
  double x, y;
  point() {}
  point(double a, double b) {
    x = a;
    y = b;
  }
  double dis(point a) { return (a.x - x) * (a.x - x) + (a.y - y) * (a.y - y); }
  double tri(point a, point b) {
    a.x -= x;
    b.x -= x;
    a.y -= y;
    b.y -= y;
    return 0.5 * fabs(a.x * b.y - a.y * b.x);
  }
};
void sf(int &x) { scanf("%d", &x); }
void sf(long long &x) { scanf("%lld", &x); }
void sf(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void sf(float &x) { scanf("%f", &x); }
void sf(double &x) { scanf("%lf", &x); }
void sf(int &x, int &y) { scanf("%d%d", &x, &y); }
void sf(float &x, float &y) { scanf("%f%f", &x, &y); }
void sf(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void sf(double &x, double &y, double &z) { scanf("%lf%lf%lf", &x, &y, &z); }
void sf(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void sf(long long &x, long long &y, long long &z) {
  scanf("%lld%lld%lld", &x, &y, &z);
}
void sf(float &x, float &y, float &z) { scanf("%u%u%u", &x, &y, &z); }
void sf(char &x) { x = getchar(); }
void sf(char *s) { scanf("%s", s); }
void sf(string &s) { cin >> s; }
void sf(point &x) {
  double a, b;
  sf(a, b);
  x = point(a, b);
}
void pf(int x) { printf("%d\n", x); }
void pf(int x, int y) { printf("%d %d\n", x, y); }
void pf(int x, int y, int z) { printf("%d %d %d\n", x, y, z); }
void pf(long long x) { printf("%lld\n", x); }
void pf(long long x, long long y) { printf("%lld %lld\n", x, y); }
void pf(long long x, long long y, long long z) {
  printf("%lld %lld %lld\n", x, y, z);
}
void pf(float x) { printf("%u\n", x); }
void pf(double x) { printf("%.9lf\n", x); }
void pf(double x, double y) { printf("%.5lf %.5lf\n", x, y); }
void pf(char x) { printf("%c\n", x); }
void pf(char *x) { printf("%s\n", x); }
void pf(string x) {
  cout << x;
  puts("");
}
template <class T>
T bigmod(T b, T p, T m) {
  if (p == 0) return 1 % m;
  T x = b;
  T ans = 1;
  while (p) {
    if (p & 1) ans = (ans * x) % m;
    p >>= 1;
    x = (x * x) % m;
  }
  return ans;
}
template <class T>
T gcd(T x, T y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
template <typename T>
T POW(T b, T p) {
  if (p == 0) return 1;
  if (p == 1) return b;
  if (p % 2 == 0) {
    T s = POW(b, p / 2);
    return s * s;
  }
  return b * POW(b, p - 1);
}
template <typename T>
T modinv(T num, T m) {
  return bigmod(num, m - 2, m);
}
int n, a[2000009], b[2000009];
int main() {
  sf(n);
  int posA = 0, posB = 0, la = 0, lb = 0;
  for (int i = 0; i < n; i++) {
    int in;
    sf(in);
    if (in != 0) {
      a[la] = in;
      la++;
    }
  }
  for (int i = 0; i < n; i++) {
    int in;
    sf(in);
    if (in != 0) {
      b[lb] = in;
      if (b[lb] == a[0]) {
        posB = lb;
      }
      lb++;
    }
  }
  int nn = n;
  while (nn--) {
    if (a[posA] != b[posB]) {
      pf("NO");
      return 0;
    }
    posA = (posA + 1 == la) ? 0 : posA + 1;
    posB = (posB + 1 == lb) ? 0 : posB + 1;
  }
  pf("YES");
  return 0;
}
