#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int n;
int a[100005];
int b[100005];
bool z4(int i) {
  return b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 && b[i - 4] == 0;
}
bool o4(int i) {
  return b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 && b[i - 4] == 1;
}
int ma(int i) {
  int res = a[i - 1];
  res = max(res, a[i]);
  res = max(res, a[i - 2]);
  res = max(res, a[i - 3]);
  res = max(res, a[i - 4]);
  return res;
}
int mi(int i) {
  int res = a[i - 1];
  res = min(res, a[i]);
  res = min(res, a[i - 2]);
  res = min(res, a[i - 3]);
  res = min(res, a[i - 4]);
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  string tem;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> tem;
  for (int i = 0; i < n; i++) b[i] = tem[i] - '0';
  int lmin = -inf, rmax = inf;
  for (int i = 4; i < n; i++) {
    if (b[i] == 1) {
      if (z4(i)) {
        lmin = max(lmin, ma(i) + 1);
      } else {
        ;
      }
    } else {
      if (o4(i)) rmax = min(rmax, mi(i) - 1);
    }
  }
  cout << lmin << " " << rmax << endl;
  return 0;
}
