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