#include <bits/stdc++.h>
using namespace std;
long long const modul = 1;
long long mod_sum(long long x, long long y) { return (x + y) % modul; }
long long mod_sub(long long x, long long y) {
  if (x > y) {
    return (x - y) % modul;
  } else {
    return (modul + x - y) % modul;
  }
}
long long mod_mpl(long long x, long long y) { return (x * y) % modul; }
void set_precise(int n) {
  cout << fixed;
  cout << setprecision(n);
}
int a[200001];
vector<int> a1;
int b[200001];
vector<int> b1;
int main() {
  int n;
  cin >> n;
  int a_pos = 0;
  int b_pos = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 1) {
      a_pos = i;
    }
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    if (b[i] == 1) {
      b_pos = i;
    }
  }
  for (int i = a_pos; i < n; ++i) {
    if (a[i] != 0) {
      a1.push_back(a[i]);
    }
  }
  for (int i = 0; i < a_pos; ++i) {
    if (a[i] != 0) {
      a1.push_back(a[i]);
    }
  }
  for (int i = b_pos; i < n; ++i) {
    if (b[i] != 0) {
      b1.push_back(b[i]);
    }
  }
  for (int i = 0; i < b_pos; ++i) {
    if (b[i] != 0) {
      b1.push_back(b[i]);
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    if (a1[i] != b1[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
