#include <bits/stdc++.h>
using namespace std;
int a[400100];
int b[400100];
int main() {
  int n;
  cin >> n;
  int k = 0;
  for (int i = 1; i <= n; i++) {
    int l;
    cin >> l;
    if (l == 0) {
      k = 1;
    } else {
      if (k == 1)
        a[i - 1] = l;
      else
        a[i] = l;
    }
  }
  k = 0;
  for (int i = 1; i <= n; i++) {
    int l;
    cin >> l;
    if (l == 0) {
      k = 1;
    } else {
      if (k == 1)
        b[i - 1] = l;
      else
        b[i] = l;
    }
  }
  int uk = n;
  int uk1 = 1;
  for (int i = 1; i < n; i++) {
    if (b[i] != a[1]) {
      b[uk] = b[i];
      uk++;
    } else {
      uk1 = i;
      break;
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i] != b[uk1]) {
      cout << "NO";
      exit(0);
    }
    uk1++;
  }
  cout << "YES";
  return 0;
}
