#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], s[200010];
int n;
void fun(int x[]) {
  for (int i = 0; i < n; i++) {
    if (x[i] == 0) {
      int k = 0;
      for (int j = i; j < n; j++) {
        s[k++] = x[j];
      }
      for (int j = 0; j < i; j++) {
        s[k++] = x[j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    x[i] = s[i];
  }
  for (int i = 0; i < n; i++) {
    if (x[i] == 1) {
      int k = 0;
      s[k++] = 0;
      for (int j = i; j < n; j++) {
        s[k++] = x[j];
      }
      for (int j = 1; j < i; j++) {
        s[k++] = x[j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    x[i] = s[i];
  }
}
int main() {
  while (~scanf("%d", &n)) {
    int fg = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
    }
    fun(a);
    fun(b);
    for (int i = 0; i < n; i++) {
      if (a[i] != b[i]) {
        fg = 0;
        break;
      }
    }
    if (fg)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
