#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  queue<long long> b;
  long long c0 = 0, c1 = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x > 0)
      a.push_back(x);
    else
      c0++;
  }
  long long Size = a.size();
  for (long long i = 0; i < Size; i++) {
    a.push_back(a[i]);
  }
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x > 0)
      b.push(x);
    else
      c1++;
  }
  if (c1 != c0) {
    cout << "NO";
    return 0;
  }
  queue<long long> temp;
  for (long long i = 0; i < Size; i++) {
    temp.push(a[i]);
  }
  for (long long i = Size; i < a.size(); i++) {
    if (temp == b) {
      cout << "YES";
      return 0;
    }
    temp.pop();
    temp.push(a[i]);
  }
  if (temp == b) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
