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