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