#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) a.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) b.push_back(x);
  }
  n--;
  int f;
  for (int i = 0; i < n; i++)
    if (a[0] == b[i]) {
      f = i;
      break;
    }
  for (int i = 0; i < n; i++)
    if (b[(i + f) % n] != a[i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
}
