#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int T[n];
  for (int i = 0; i < n; ++i) cin >> T[i];
  string s;
  cin >> s;
  int maxp, minl;
  minl = -1000000000;
  maxp = 1000000000;
  int lc = 4;
  char lch = '0';
  for (int i = 4; i < n; ++i) {
    if (s[i] != lch) {
      lc = 1;
      lch = s[i];
      if (lch == '0') {
        int m5 = T[i - 4];
        for (int j = 0; j < 4; ++j) m5 = min(m5, T[i - j]);
        maxp = min(maxp, m5 - 1);
      } else {
        int m5 = T[i - 4];
        for (int j = 0; j < 4; ++j) m5 = max(m5, T[i - j]);
        minl = max(minl, m5 + 1);
      }
    }
  }
  cout << minl << " " << maxp << endl;
}
