#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a, b;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x != 0) a.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x != 0) b.push_back(x);
  }
  int p1 = 0;
  int p2 = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == 1) p1 = i;
    if (b[i] == 1) p2 = i;
  }
  for (int i = 0; i < n; i++) {
    if (a[(p1 + i) % (int)(a).size()] != b[(p2 + i) % (int)(b).size()]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
