#include <bits/stdc++.h>
using namespace std;
inline int rint() {
  int a;
  scanf("%d", &a);
  return a;
}
inline long long rll() {
  long long a;
  scanf("%lld", &a);
  return a;
}
inline double rdouble() {
  double a;
  scanf("%lf", &a);
  return a;
}
int a[100005];
string b;
int main() {
  int n = rint();
  for (int i = 1; i <= n; i++) a[i] = rint();
  cin >> b;
  b = "0" + b;
  int lmin = -1e9, lmax = 1e9, rmin = -1e9, rmax = 1e9;
  int cnt = 4;
  for (int i = 5; i <= n; i++) {
    if (cnt >= 4) {
      int maxx = max(max(a[i - 1], a[i - 2]), max(a[i - 3], a[i - 4]));
      maxx = max(maxx, a[i]);
      int minn = min(min(a[i - 1], a[i - 2]), min(a[i - 3], a[i - 4]));
      minn = min(minn, a[i]);
      if (b[i - 1] == '0' && b[i] == '0') lmax = min(lmax, maxx);
      if (b[i - 1] == '0' && b[i] == '1') lmin = max(lmin, maxx + 1);
      if (b[i - 1] == '1' && b[i] == '1') rmin = max(rmin, minn);
      if (b[i - 1] == '1' && b[i] == '0') rmax = min(rmax, minn - 1);
    } else
      cnt++;
  }
  cout << lmin << " " << rmax << endl;
  return 0;
}
