#include <bits/stdc++.h>
char b[100005];
int a[100005];
int max(int c, int d) { return c > d ? c : d; }
int min(int c, int d) { return c < d ? c : d; }
int main() {
  int n, rmax = 1000000000, lmax = INT_MAX, rmin = INT_MIN, lmin = -1000000000;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%s", b);
  for (int i = 4; i < n; i++) {
    if (b[i - 1] != b[i - 2] || b[i - 3] != b[i - 2] || b[i - 3] != b[i - 4])
      continue;
    else {
      if (b[i] == '1' && b[i - 1] == '0')
        lmin = max(
            max(max(max(a[i - 4], a[i - 3]), max(a[i - 2], a[i - 1])), a[i]) +
                1,
            lmin);
      if (b[i] == '0' && b[i - 1] == '1')
        rmax = min(
            min(min(min(a[i - 4], a[i - 3]), min(a[i - 2], a[i - 1])), a[i]) -
                1,
            rmax);
    }
  }
  printf("%d %d", lmin, rmax);
}
