#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 5, INF = 1E9;
int a[N], n;
char b[N];
pair<int, int> range(int i) {
  int first, second;
  first = min(a[i], min(min(a[i - 4], a[i - 3]), min(a[i - 2], a[i - 1])));
  second = max(a[i], max(max(a[i - 4], a[i - 3]), max(a[i - 2], a[i - 1])));
  return pair<int, int>(first, second);
}
int main() {
  int i;
  char pre;
  pair<int, int> left, right;
  left = right = pair<int, int>(-INF, INF);
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", a + i);
  scanf("%s", b);
  i = 4;
  pre = '0';
  while (i < n) {
    pair<int, int> rg = range(i);
    if (b[i] != pre) {
      if (pre == '0')
        left.first = max(left.first, rg.second + 1);
      else
        right.second = min(right.second, rg.first - 1);
      pre = b[i];
      i += 4;
    } else {
      if (pre == '0')
        left.second = min(left.second, rg.second);
      else
        right.first = max(right.first, rg.first);
      i++;
    }
  }
  printf("%d %d", left.first, right.second);
  return 0;
}
