#include <bits/stdc++.h>
using namespace std;
int A[100005], B[100005];
int l = -1e9, r = 1e9, n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) scanf("%1d", &B[i]);
  for (int i = 5, minv, maxv, fg; i <= n; i++) {
    minv = min(min(min(A[i - 1], A[i - 2]), min(A[i - 3], A[i - 4])), A[i]);
    maxv = max(max(max(A[i - 1], A[i - 2]), max(A[i - 3], A[i - 4])), A[i]);
    fg = B[i - 1] + B[i - 2] + B[i - 3] + B[i - 4];
    if (fg == 0 && B[i] == 1)
      l = max(l, maxv + 1);
    else if (fg == 4 && B[i] == 0)
      r = min(r, minv - 1);
  }
  printf("%d %d\n", l, r);
  return 0;
}
