#include <bits/stdc++.h>
using namespace std;
int a[222222];
int b[222222];
int main() {
  int n;
  cin >> n;
  if (n == 2) {
    puts("YES");
    return 0;
  }
  int prev = 0;
  int start;
  int x;
  start = -228;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) {
      if (start == -228) {
        start = x;
      }
      a[x] = prev;
      prev = x;
    }
  }
  a[start] = ((x == 0) ? prev : x);
  start = -228;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x != 0) {
      if (start == -228) {
        start = x;
      }
      b[x] = prev;
      prev = x;
    }
  }
  b[start] = ((x == 0) ? prev : x);
  int ans = 1;
  for (int i = 0; i <= n; i++) {
    ans &= (a[i] == b[i]);
  }
  puts((ans) ? "YES" : "NO");
  return 0;
}
