#include <bits/stdc++.h>
using namespace std;
int store[200005];
int cmp[200005];
int main(void) {
  int n;
  scanf("%d", &n);
  int cnt = 0;
  for (int i = 0; i < (n); ++i) {
    scanf("%d", store + cnt);
    if (store[cnt] != 0) cnt++;
  }
  cnt = 0;
  for (int i = 0; i < (n); ++i) {
    scanf("%d", cmp + cnt);
    if (cmp[cnt] != 0) cnt++;
  }
  for (int i = 0; i < (cnt); ++i)
    if (store[i] == cmp[0]) {
      for (int j = 0; j < (cnt); ++j) {
        if (store[(i + j) % cnt] != cmp[j]) {
          puts("NO");
          return 0;
        }
      }
      break;
    }
  puts("YES");
  return 0;
}
