#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 1e5 + 100;
int b[maxn], a[maxn];
vector<int> litl, litr, bigl, bigr;
int main() {
  int n;
  string st, s;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> st;
  s = '0' + st;
  for (int i = 5; i <= n; i++) {
    if (s[i] == '1') {
      if (s[i - 1] == '0' and s[i - 2] == '0' and s[i - 3] == '0' and
          s[i - 4] == '0') {
        int mxx = -1000 * 1000 * 1000;
        for (int j = i; j >= i - 4; j--) mxx = max(mxx, a[j]);
        litl.push_back(mxx);
      }
    } else {
      if (s[i - 1] == '1' and s[i - 2] == '1' and s[i - 3] == '1' and
          s[i - 4] == '1') {
        int mnn = 1000 * 1000 * 1000;
        for (int j = i; j >= i - 4; j--) mnn = min(mnn, a[j]);
        bigr.push_back(mnn);
      }
    }
  }
  sort(litl.begin(), litl.end());
  if (litl.empty())
    cout << -1000 * 1000 * 1000 << " ";
  else
    cout << litl.back() + 1 << " ";
  sort(bigr.begin(), bigr.end());
  if (bigr.empty())
    cout << 1000 * 1000 * 1000 << " ";
  else
    cout << bigr[0] - 1 << endl;
}
