#include <bits/stdc++.h>
using namespace std;
int n, i, j, a[100005], l, r;
string s;
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  ;
  cin >> n;
  for (__typeof(i) i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> s;
  l = -1000000000;
  r = 1000000000;
  int cur = 0;
  int m = 0;
  for (__typeof(i) i = 4; i < n; ++i) {
    if (s[i] - '0' != cur) {
      if (cur) {
        m = INT_MAX;
        for (__typeof(j) j = -4; j <= 0; ++j) {
          m = min(m, a[i + j]);
        }
        r = min(r, m - 1);
        cur = 0;
      } else {
        m = INT_MIN;
        for (__typeof(j) j = -4; j <= 0; ++j) {
          m = max(m, a[i + j]);
        }
        l = max(l, m + 1);
        cur = 1;
      }
    }
  }
  cout << l << " " << r << endl;
  return 0;
}
