#include <bits/stdc++.h>
using namespace std;
const long long MAX = (long long)1000 * 1000 * 1000 * 1000 * 1000 * 1000;
int n;
void read(vector<int>& a) {
  int k = 0;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    if (a[i] == 0) k = i;
  }
  for (int i = (k - 1); i > (-1); i--) a[i + 1] = a[i];
  a[0] = 0;
}
bool isEquel(vector<int>& a, vector<int>& b) {
  for (int i = (0); i < (n); i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vector<int> a(n), b(n);
  read(a);
  read(b);
  int k;
  for (int i = (1); i < (n); i++)
    if (a[1] == b[i]) k = i;
  vector<int> bb;
  bb.push_back(0);
  for (int i = (k); i < (n); i++) bb.push_back(b[i]);
  for (int i = (1); i < (k); i++) bb.push_back(b[i]);
  if (isEquel(a, bb)) {
    cout << "YES" << '\n';
    return 0;
  }
  cout << "NO" << '\n';
  return 0;
}
