#include <bits/stdc++.h>
using namespace std;
using namespace std;
void preKMP(basic_string<char> pattern, int f[]) {
  int m = pattern.length(), k;
  f[0] = -1;
  for (int i = 1; i < m; i++) {
    k = f[i - 1];
    while (k >= 0) {
      if (pattern[k] == pattern[i - 1])
        break;
      else
        k = f[k];
    }
    f[i] = k + 1;
  }
}
bool KMP(basic_string<char> pattern, basic_string<char> target) {
  int m = pattern.length();
  int n = target.length();
  int f[m];
  preKMP(pattern, f);
  int i = 0;
  int k = 0;
  while (i < n) {
    if (k == -1) {
      i++;
      k = 0;
    } else if (target[i] == pattern[k]) {
      i++;
      k++;
      if (k == m) return 1;
    } else
      k = f[k];
  }
  return 0;
}
int main() {
  basic_string<char> tar;
  basic_string<char> pat;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    char c;
    c = x;
    if (x != 0) pat.push_back(c);
  }
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    char c;
    c = x;
    if (x != 0) tar.push_back(c);
  }
  tar = (tar + tar) + tar;
  if (KMP(pat, tar))
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
