#include <bits/stdc++.h>
using namespace std;
int n, a[100005], b[100005] = {0}, cntb[5] = {0}, l, r, mx[100005], mn[100005],
                  upr = 1e9, downr = -1e9, upl = 1e9, downl = -1e9;
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> s;
  for (int i = 1; i <= n; i++) b[i] = s[i - 1] - '0';
  for (int i = 1; i <= 4; i++) cntb[b[i]]++;
  for (int i = 5; i <= n; i++) {
    int m1 = 1e9, m2 = -1e9;
    for (int j = i; j >= i - 4; j--) {
      m1 = min(m1, a[j]);
      m2 = max(m2, a[j]);
    }
    mx[i] = m2;
    mn[i] = m1;
  }
  for (int i = 5; i <= n; i++) {
    if (cntb[0] == 4) {
      if (b[i] == 1) {
        downl = max(downl, mx[i] + 1);
      }
    } else if (cntb[1] == 4) {
      if (b[i] == 0) {
        upr = min(upr, mn[i] - 1);
      }
    }
    cntb[b[i - 4]]--;
    cntb[b[i]]++;
  }
  cout << downl << ' ' << upr << endl;
  return 0;
}
