#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, l, m, n, mn = 1000000000, r, mx = -1000000000;
  cin >> n;
  int ar[n + 10];
  for (i = 1; i <= n; i++) {
    cin >> ar[i];
  }
  string s;
  cin >> s;
  s = '*' + s;
  int got1, got2;
  got1 = got2 = 0;
  char ch;
  int cnt, ke;
  l = -1000000000;
  r = 1000000000;
  for (i = 1; i <= n - 4; i++) {
    ch = s[i];
    cnt = 0;
    for (j = i; j < i + 4; j++) {
      cnt += (ch == s[j]);
    }
    if (cnt == 4) {
      if (ch == '0') {
        if (s[i + 4] == '1') {
          ke = max({ar[i + 4], ar[i + 3], ar[i + 2], ar[i + 1], ar[i]});
          l = max(l, ke + 1);
        } else {
          ke = max({ar[i + 4], ar[i + 3], ar[i + 2], ar[i + 1], ar[i]});
          l = min(l, ke);
        }
      } else {
        if (s[i + 4] == '0') {
          ke = min({ar[i + 4], ar[i + 3], ar[i + 2], ar[i + 1], ar[i]});
          r = min(r, ke - 1);
        } else {
          ke = min({ar[i + 4], ar[i + 3], ar[i + 2], ar[i + 1], ar[i]});
          r = max(r, ke);
        }
      }
    }
  }
  cout << l << " " << r << '\n';
}
