#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
const long long MOD = 1e9 + 7;
int n, a[N], mx[N], mn[N];
char s[N + 2];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  scanf("%s", s);
  for (int i = 4; i < n; i++) {
    mx[i] = max(max(max(max(a[i], a[i - 1]), a[i - 2]), a[i - 3]), a[i - 4]);
    mn[i] = min(min(min(min(a[i], a[i - 1]), a[i - 2]), a[i - 3]), a[i - 4]);
  }
  int l = -1000000000, r = 1000000000;
  for (int i = 4; i < n; i++) {
    if (s[i] == '1') {
      if (s[i - 1] == '0') {
        if (s[i - 2] == '0' && s[i - 3] == '0' && s[i - 4] == '0')
          l = max(l, mx[i] + 1);
      }
    } else {
      if (s[i - 1] == '1') {
        if (s[i - 2] == '1' && s[i - 3] == '1' && s[i - 4] == '1')
          r = min(r, mn[i] - 1);
      }
    }
  }
  printf("%d %d\n", l, r);
  return 0;
}
