#include <bits/stdc++.h>
const int mod = 1e9 + 9;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 50;
const int root = 1e6 + 7;
using namespace std;
long long n, m, l, r, k;
int a[maxn];
string b;
int mi, ma;
void slove(int x) {
  mi = 1e9 + 1;
  ma = -1e9 - 1;
  for (int i = x - 4; i <= x; i++) {
    mi = min(a[i], mi);
    ma = max(a[i], ma);
  }
}
bool judge(int x, int po) {
  if (x) {
    for (int i = po - 1; i >= po - 4; i--) {
      if (b[i] != '1') return false;
    }
    return true;
  } else {
    for (int i = po - 1; i >= po - 4; i--) {
      if (b[i] != '0') return false;
    }
    return true;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> b;
  l = -1e9;
  r = 1e9;
  for (int i = 4; i < n; i++) {
    if (b[i] == '0' && judge(1, i)) {
      slove(i + 1);
      r = min(r, (long long)mi - 1);
    } else if (b[i] == '1' && judge(0, i)) {
      slove(i + 1);
      l = max(l, (long long)ma + 1);
    }
  }
  cout << l << ' ' << r << endl;
  return 0;
}
