#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = 0x3f3f3f3f, maxnum = 1e9;
int a[maxn];
char b[maxn];
int n;
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  scanf("%s", b);
  int lu = inf, ld = -inf, ru = inf, rd = -inf;
  for (int i = 4; i < n; i++) {
    if (b[i - 1] == b[i - 2] && b[i - 2] == b[i - 3] && b[i - 3] == b[i - 4]) {
      if (b[i - 1] == '1') {
        if (b[i] == '0')
          for (int j = 0; j <= 4; j++) ru = min(ru, a[i - j]);
        else {
          int tmp = inf;
          for (int j = 0; j <= 4; j++) tmp = min(tmp, a[i - j]);
          rd = max(tmp, rd);
        }
      } else {
        if (b[i] == '1')
          for (int j = 0; j <= 4; j++) ld = max(ld, a[i - j]);
        else {
          int tmp = -inf;
          for (int j = 0; j <= 4; j++) tmp = max(tmp, a[i - j]);
          lu = min(tmp, lu);
        }
      }
    }
  }
  cout << max(-maxnum, ld + 1) << " " << min(ru - 1, maxnum) << endl;
}
