#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
int n, arr[200011], b[200011];
int main() {
  cin >> n;
  int x;
  bool z = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0) {
      z = 1;
      continue;
    }
    arr[x] = i + 1 - z;
  }
  z = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 0)
      z = 1;
    else
      b[i - z] = arr[x];
  }
  bool can = 1;
  for (int i = 0; i < n - 2; i++)
    if (b[i] + 1 == b[i + 1])
      continue;
    else {
      can = 0;
      break;
    }
  if (can) {
    cout << "YES";
    return 0;
  }
  can = 1;
  for (int i = 0; i < n - 2; i++)
    if (b[i] + 1 == b[i + 1])
      continue;
    else {
      for (int j = i + 1; j < n - 2; j++)
        if (b[j] + 1 != b[j + 1]) {
          can = 0;
          break;
        }
      break;
    }
  if (can) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
