#include <bits/stdc++.h>
const int maxn = 1e9;
const double EI =
    2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427;
using namespace std;
int c[1000100];
char d[1000100];
int main(void) {
  int n, i, j, k, l, r, mm, mi;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; i++) {
      scanf("%d", c + i);
    }
    scanf("%s", d);
    l = -1000000000;
    r = 1000000000;
    for (i = 4; i < n; i++) {
      if (d[i] == '0' && d[i - 1] == '1' && d[i - 2] == '1' &&
          d[i - 3] == '1' && d[i - 4] == '1') {
        for (j = i; j >= i - 4; j--) {
          r = min(r, c[j] - 1);
        }
      } else if (d[i] == '1' && d[i - 1] == '0' && d[i - 2] == '0' &&
                 d[i - 3] == '0' && d[i - 4] == '0') {
        for (j = i; j >= i - 4; j--) {
          l = max(l, c[j] + 1);
        }
      }
    }
    printf("%d %d\n", l, r);
  }
  return 0;
}
