#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 100;
bool mark;
int n, a[maxN], b[maxN], x, y;
int main() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    if (mark)
      cin >> a[i - 1];
    else
      cin >> a[i];
    if (!a[i]) mark = true;
    if (a[i - 1] == 1) x = i - 1;
  }
  mark = false;
  for (long long int i = 1; i <= n; i++) {
    if (mark)
      cin >> b[i - 1];
    else
      cin >> b[i];
    if (!b[i]) mark = true;
    if (b[i - 1] == 1) y = i - 1;
  }
  for (long long int i = 1; i <= n; i++) {
    x++;
    y++;
    if (x == n) x = 1;
    if (y == n) y = 1;
    if (a[x] != b[y]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
