#include <bits/stdc++.h>
using namespace std;
const int debug = 0;
const int INF = 1e9 + 7;
int n, l = -1e9, r = 1e9;
int a[100005];
bool ul, ur;
char b[100005];
bool Check(int cur, int st, int ed, bool smaller) {
  for (int i = st; i <= ed; i++) {
    if (smaller && cur <= a[i]) return 0;
    if (!smaller && cur >= a[i]) return 0;
  }
  return 1;
}
int Find(int st, int ed, bool smaller) {
  int ret;
  if (smaller)
    ret = -INF;
  else
    ret = INF;
  for (int i = st; i <= ed; i++) {
    if (smaller)
      ret = max(ret, a[i]);
    else
      ret = min(ret, a[i]);
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  scanf("\n%s", b);
  for (int i = 4; i < n; i++) {
    bool f0 = 1, f1 = 1;
    for (int j = i - 4; j < i; j++) {
      if (b[j] == '1')
        f0 = 0;
      else
        f1 = 0;
    }
    if (b[i] == '0' && f1) {
      if (!ur || !Check(r, i - 4, i, 0)) {
        ur = 1;
        r = Find(i - 4, i, 0) - 1;
      }
    } else if (b[i] == '1' && f0) {
      if (!ul || !Check(l, i - 4, i, 1)) {
        ul = 1;
        l = Find(i - 4, i, 1) + 1;
      }
    } else if (b[i] == b[i - 1]) {
    }
  }
  if (l > r) {
    if (!ul)
      l = r - 1;
    else
      r = l + 1;
  }
  printf("%d %d\n", l, r);
  return 0;
}
