#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
string b;
bool check(int pos, char what) {
  if (b[pos - 1] == what && b[pos - 2] == what && b[pos - 3] == what &&
      b[pos - 4] == what) {
    return true;
  }
  return false;
}
int get_max(int pos, int* T) {
  return max(T[pos],
             max(T[pos - 1], max(T[pos - 2], max(T[pos - 3], T[pos - 4]))));
}
int get_min(int pos, int* T) {
  return min(T[pos],
             min(T[pos - 1], min(T[pos - 2], min(T[pos - 3], T[pos - 4]))));
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int T[n];
  for (int i = 0; i < n; i++) cin >> T[i];
  cin >> b;
  int start = 4;
  int l_low, l_top, r_low, r_top;
  l_low = l_top = r_low = r_top = 0;
  for (int i = start; i < n; i++) {
    if (check(i, '0')) {
      if (b[i] == '1') {
        l_low = max(get_max(i, T) + 1, l_low);
        l_top = max(l_top, l_low);
      } else {
        l_top = min(get_max(i, T), l_top);
        l_low = min(l_low, l_top);
      }
      r_low = max(r_low, l_top);
      r_top = max(r_top, r_low);
    }
    if (check(i, '1')) {
      if (b[i] == '0') {
        r_top = min(get_min(i, T) - 1, r_top);
        r_low = min(r_top, r_low);
      } else {
        r_low = max(get_min(i, T), r_low);
        r_top = max(r_low, r_top);
      }
      l_top = min(r_low, l_top);
      l_low = min(l_low, l_top);
    }
  }
  cout << l_low << " " << r_top << endl;
}
