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