#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], n;
string b;
int main() {
  long long l, r, ubl = 1e9, lbl = -1e9, ubr = 1e9, lbr = -1e9;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  cin >> b;
  bool last = 0;
  for (int i = 4; i < n; i++) {
    long long mx = -1e9, mn = 1e9;
    for (int j = i; j >= i - 4; --j)
      mx = max(mx, (long long)a[j]), mn = min(mn, (long long)a[j]);
    if (last == 0 && b[i] == '1') {
      lbl = max(lbl, mx + 1);
      i += 3;
      last = 1;
      continue;
    }
    if (last == 0 && b[i] == '0') ubl = min(ubl, mx - 1);
    if (last == 1 && b[i] == '1') lbr = max(lbr, mn + 1);
    if (last == 1 && b[i] == '0') {
      ubr = min(ubr, mn - 1);
      i += 3;
      last = 0;
    }
  }
  cout << lbl << " " << ubr;
}
