#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%d", &c);
    a.push_back(c);
  }
  int u, ub;
  a[0] == 0 ? u = 1 : u = 0;
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%d", &c);
    b.push_back(c);
    if (b[i] == a[u]) ub = i;
  }
  int i = 0, x = u, y = ub;
  while (i < n) {
    if (a[x] != b[y]) {
      cout << "NO";
      return 0;
    }
    x++;
    if (a[x] == 0) x++;
    if (x >= n) x = 0;
    if (a[x] == 0) x++;
    y++;
    if (b[y] == 0) y++;
    if (y >= n) y = 0;
    if (b[y] == 0) y++;
    i++;
  }
  cout << "YES";
  return 0;
}
