#include <bits/stdc++.h>
using namespace std;
const int MX = 1147483646;
const long long MX2 = 9223372036854775800;
const int MOD = 1000000007;
int main() {
  int n, i, arr[100011];
  char s[100011];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  scanf("%s", s);
  pair<int, int> ansl = {-1000000000, 1000000000},
                 ansr = {-1000000000, 1000000000};
  int cnt = 4;
  for (i = 4; i < n; i++) {
    if (cnt >= 4) {
      if (s[i] != s[i - 1]) {
        if (s[i] == '1') {
          ansl.first = max(ansl.first, max({arr[i], arr[i - 1], arr[i - 2],
                                            arr[i - 3], arr[i - 4]}) +
                                           1);
        } else {
          ansr.second = min(ansr.second, min({arr[i], arr[i - 1], arr[i - 2],
                                              arr[i - 3], arr[i - 4]}) -
                                             1);
        }
      } else {
        if (s[i] == '0') {
          ansl.second = min(ansl.second, max({arr[i], arr[i - 1], arr[i - 2],
                                              arr[i - 3], arr[i - 4]}));
        } else {
          ansr.first = max(ansr.first, min({arr[i], arr[i - 1], arr[i - 2],
                                            arr[i - 3], arr[i - 4]}));
        }
      }
    }
    if (s[i] == s[i - 1])
      cnt++;
    else
      cnt = 1;
  }
  printf("%d %d", ansl.first, ansr.second);
  return 0;
}
