#include <bits/stdc++.h>
using namespace std;
const int MAX_D = 200010;
int n, a[MAX_D], b[MAX_D];
vector<int> a1;
vector<int> b1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int w1 = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      w1 = i;
    }
    if (w1 != 0 && a[i] != 0) {
      a1.push_back(a[i]);
    }
  }
  for (int i = 1; i < w1; i++)
    if (a[i] != 0) {
      a1.push_back(a[i]);
    }
  int w2 = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == 1) {
      w2 = i;
    }
    if (w2 != 0 && b[i] != 0) {
      b1.push_back(b[i]);
    }
  }
  for (int i = 1; i < w2; i++) {
    if (b[i] != 0) {
      b1.push_back(b[i]);
    }
  }
  bool falg = true;
  for (int i = 0; i < a1.size(); i++) {
    if (a1[i] != b1[i]) {
      falg = false;
    }
  }
  if (falg && (a1.size() == b1.size())) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}
