#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> v, v1, v2;
string s;
long long a[6], b[1000000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    v.push_back(k);
  }
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      b[i] = 0;
    } else
      b[i] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (b[i] != b[i - 1]) {
      if (b[i] == 0) {
        for (int j = i - 4; j <= i; j++) v2.push_back(v[j]);
      } else {
        for (int j = i - 4; j <= i; j++) v1.push_back(v[j]);
      }
    }
  }
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1.size() == 0 && v2.size() == 0) {
    cout << v[0] - 1 << " " << v[v.size() - 1] + 2;
    return 0;
  }
  if (v1.size() == 0) {
    cout << v[0] - 100 << " " << v2[0] - 1;
    return 0;
  }
  if (v2.size() == 0) {
    cout << v1[v1.size() - 1] + 1 << " " << v[v.size() - 1] + 1000;
    return 0;
  }
  cout << v1[v1.size() - 1] + 1 << " " << v2[0] - 1;
}
