#include <bits/stdc++.h>
using namespace std;
void normalize(vector<int> &a) {
  deque<int> b;
  int mn = 1e9;
  for (int i = 0; i < a.size(); ++i) {
    b.push_back(a[i]);
    mn = min(mn, a[i]);
  }
  while (b.front() != mn) {
    b.push_front(b.back());
    b.pop_back();
  }
  a.clear();
  for (int i = 0; i < b.size(); ++i) {
    a.push_back(b[i]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a;
  for (int i = 0; i < n; ++i) {
    int foo;
    scanf("%d", &foo);
    if (foo != 0) {
      a.push_back(foo);
    }
  }
  vector<int> b;
  for (int i = 0; i < n; ++i) {
    int foo;
    scanf("%d", &foo);
    if (foo != 0) {
      b.push_back(foo);
    }
  }
  normalize(a);
  normalize(b);
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] != b[i]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
