#include <bits/stdc++.h>
using namespace std;
int A[1000010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i];
  string s;
  cin >> s;
  int la = -1e9, ha = 1e9, lb = -1e9, hb = 1e9;
  multiset<int> fg;
  for (int i = 0; i < 4; i++) fg.insert(A[i]);
  for (int i = 4; i < n; i++) {
    fg.insert(A[i]);
    if (s[i] == '0') {
      if (s[i - 1] == '0') {
        if (s[i - 1] == '0' && s[i - 2] == '0' && s[i - 3] == '0' &&
            s[i - 4] == '0') {
          ha = min(la, *fg.rbegin());
        }
      } else {
        hb = min(hb, *fg.begin() - 1);
      }
    } else if (s[i] == '1') {
      if (s[i - 1] == '1') {
        if (s[i - 1] == '1' && s[i - 2] == '1' && s[i - 3] == '1' &&
            s[i - 4] == '1') {
          lb = max(lb, *fg.begin());
        }
      } else {
        la = max(la, (*fg.rbegin()) + 1);
      }
    }
    fg.erase(fg.find(A[i - 4]));
  }
  cout << la << " " << hb << '\n';
}
