#include <bits/stdc++.h>
using namespace std;
int a[110000], n;
char b[110000];
int main() {
  scanf("%d", &n);
  int i, j, s, p, q;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%s", b);
  int al, bl, ar, br;
  al = 1e9;
  bl = -1e9;
  ar = 1e9;
  br = -1e9;
  for (i = 4; i < n; i++) {
    if (b[i] == b[i - 1]) {
      if (b[i] == '0') {
        for (j = i; j >= i - 4; j--) al = min(al, a[j]);
      } else {
        for (j = i; j >= i - 4; j--) br = max(br, a[j]);
      }
    } else {
      if (b[i] == '0') {
        for (j = i; j >= i - 4; j--) ar = min(ar, a[j] - 1);
      } else {
        for (j = i; j >= i - 4; j--) bl = max(bl, a[j] + 1);
      }
      i += 4;
    }
  }
  printf("%d %d\n", bl, ar);
}
