#include <bits/stdc++.h>
using namespace std;
int n, a[100005], lmini = -1000000000, rmini = -1000000000;
string bin;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> bin;
  for (int i = 4; i < bin.size(); i++)
    if (bin[i - 1] == bin[i - 2] && bin[i - 1] == bin[i - 3] &&
        bin[i - 1] == bin[i - 4]) {
      if (bin[i - 1] == '1' && bin[i] == '1')
        rmini = max(*min_element(a + i - 4, a + i + 1), rmini);
      else if (bin[i - 1] == '0' && bin[i] == '1')
        lmini = max(*max_element(a + i - 4, a + i + 1) + 1, lmini);
    }
  cout << lmini << " " << max(lmini, rmini) << endl;
  return 0;
}
