#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, a, b, l;
vector<int> v1, v2;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (a != 0) v1.push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (a != 0) v2.push_back(a);
  }
  for (int i = 0; i < n - 1; i++) v2.push_back(v2[i]);
  for (int i = 0; i < v2.size(); i++)
    if (v2[i] == v1[0]) {
      l = i;
      break;
    }
  for (int i = 0; i < n - 1; i++)
    if (v1[i] != v2[i + l]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
