#include <bits/stdc++.h>
using namespace std;
int main() {
  long long ara[100009];
  long long i, j, k, l, r, m, n;
  string b;
  cin >> n;
  for (i = 0; i < n; i++) cin >> ara[i];
  cin >> b;
  l = -1000000000, r = 1000000000;
  for (i = 4; i < n;) {
    if (b[i] == '1' && b[i - 1] == '0' && b[i - 2] == '0' && b[i - 3] == '0' &&
        b[i - 4] == '0') {
      vector<long long> v;
      for (j = i; j >= i - 4; j--) {
        v.push_back(ara[j]);
      }
      sort(v.begin(), v.end());
      l = max(l, v[v.size() - 1] + 1);
      i += 5;
    } else if (b[i] == '0' && b[i - 1] == '1' && b[i - 2] == '1' &&
               b[i - 3] == '1' && b[i - 4] == '1') {
      vector<long long> v;
      for (j = i; j >= i - 4; j--) {
        v.push_back(ara[j]);
      }
      sort(v.begin(), v.end());
      r = min(r, v[0] - 1);
      i += 5;
    } else {
      i++;
    }
  }
  cout << l << " " << r << endl;
  return 0;
}
