#include <bits/stdc++.h>
long long minn = INT_MAX;
long long maxx = INT_MIN;
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n - 1), b(n - 1);
  long long j = 0;
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    if (num != 0) {
      a[j] = num;
      j++;
    }
  }
  long long pos;
  j = 0;
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    if (num != 0) {
      b[j] = num;
      if (num == a[0]) pos = j;
      j++;
    }
  }
  vector<long long> ans(n - 1);
  j = 0;
  for (long long i = pos; i < n - 1; i++) {
    ans[j] = b[i];
    j++;
  }
  for (long long i = 0; i < pos; i++) {
    ans[j] = b[i];
    j++;
  }
  for (long long i = 0; i < n - 1; i++) {
    if (ans[i] != a[i]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}
