#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s;
  cin >> s;
  long long l = -1000000001;
  long long r = 1000000001;
  for (long long i = 4; i < n; i++) {
    if (s[i] != s[i - 1]) {
      if (s[i] == '1') {
        l = max({l, a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]});
      } else {
        r = min({r, a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]});
      }
    }
  }
  l++;
  r--;
  cout << l << " " << r << endl;
}
