#include <bits/stdc++.h>
using namespace std;
vector<int> va;
vector<int> vb;
map<int, int> m;
int c = 1;
int id(int x) {
  if (m.find(x) == m.end()) m[x] = c++;
  return m[x];
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int(i) = (0); (i) < (n); ++(i)) {
    int x;
    cin >> x;
    if (x == 0) continue;
    va.push_back(id(x));
  }
  int pos = -1;
  bool f = false;
  for (int(i) = (0); (i) < (n); ++(i)) {
    int x;
    cin >> x;
    if (x == 0) {
      f = true;
      continue;
    }
    vb.push_back(id(x));
    if (id(x) == 1) pos = i - f;
  }
  bool flag = true;
  for (int(i) = (0); (i) < (n - 1); ++(i)) {
    int j = (i + pos) % (n - 1);
    if (vb[j] != va[i]) {
      flag = false;
      break;
    }
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
  return 0;
}
