#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l = -1000000000, r = 1000000000;
  long long n;
  scanf("%lld", &n);
  long long arr[n];
  for (long long i = 0; i < n; i++) scanf("%lld", &arr[i]);
  string str;
  cin >> str;
  for (long long i = 4; i < n; i++) {
    if (str[i] == '0') {
      if (str[i - 1] == '1' && str[i - 2] == '1' && str[i - 3] == '1' &&
          str[i - 4] == '1') {
        r = min(r, arr[i - 1]);
        r = min(r, arr[i - 2]);
        r = min(r, arr[i - 3]);
        r = min(r, arr[i - 4]);
        r = min(r, arr[i]);
      }
    } else if (str[i] == '1') {
      if (str[i - 1] == '0' && str[i - 2] == '0' && str[i - 3] == '0' &&
          str[i - 4] == '0') {
        l = max(l, arr[i - 1]);
        l = max(l, arr[i - 2]);
        l = max(l, arr[i - 3]);
        l = max(l, arr[i - 4]);
        l = max(l, arr[i]);
      }
    }
  }
  r--;
  l++;
  cout << l << " " << r;
}
