#include <bits/stdc++.h>
using namespace std;
const int maxn = 200080;
int a[maxn], b[maxn];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int cur;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int l = 0;
    while (a[l] != 0) l++;
    int r = l;
    while (r < n - 1) a[r] = a[r + 1], r++;
    for (int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
    }
    l = 0;
    while (b[l] != 0) l++;
    r = l;
    while (r < n - 1) b[r] = b[r + 1], r++;
    for (int i = 0; i < n - 1; i++) {
      if (a[0] == b[i]) cur = i;
    }
    int ok = 1;
    for (int i = 1; i < n - 1; i++) {
      int j = (i + cur) % (n - 1);
      if (a[i] != b[j]) {
        ok = 0;
        break;
      }
    }
    if (!ok) {
      int l = 0, r = n - 1;
      while (l <= r) {
        swap(a[l], a[r]);
        swap(b[l], b[r]);
        l++, r--;
      }
      for (int i = 0; i < n - 1; i++) {
        if (a[0] == b[i]) cur = i;
      }
      ok = 1;
      for (int i = 1; i < n - 1; i++) {
        int j = (i + cur) % (n - 1);
        if (a[i] != b[j]) {
          ok = 0;
          break;
        }
      }
    }
    if (ok)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
