#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  long long maxr = 1000000000;
  long long minr = -1000000000;
  long long maxl = 1000000000;
  long long minl = -1000000000;
  for (int i = 4; i < n; i++) {
    long long max_now =
        max(max(max(max(a[i], a[i - 1]), a[i - 2]), a[i - 3]), a[i - 4]);
    long long min_now =
        min(min(min(min(a[i], a[i - 1]), a[i - 2]), a[i - 3]), a[i - 4]);
    if (s[i] == '0' && s[i - 1] == '0') {
      minr = max(minr, min_now);
    } else if (s[i] == '0' && s[i - 1] == '1') {
      maxr = min(maxr, min_now - 1);
      i += 3;
    } else if (s[i] == '1' && s[i - 1] == '0') {
      minl = max(minl, max_now + 1);
      i += 3;
    } else if (s[i] == '1' && s[i - 1] == '1') {
      maxl = min(maxl, max_now);
    }
  }
  cout << minl << ' ' << maxr << endl;
}
