#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
const int inf = 1e9;
int n, m, x, y, q, a[maxn], flag, ans, l, r;
string b;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  cin >> b;
  m = b.size();
  l = -1e9, r = 1e9;
  for (int i = 4; i < m; i++) {
    if (b[i] == '1') {
      if (b[i - 1] == '0' && b[i - 2] == '0' && b[i - 3] == '0' &&
          b[i - 4] == '0') {
        l = max({l, a[i - 1], a[i - 2], a[i - 3], a[i - 4], a[i]});
      }
    }
    if (b[i] == '0') {
      if (b[i - 1] == '1' && b[i - 2] == '1' && b[i - 3] == '1' &&
          b[i - 4] == '1') {
        r = min({r, a[i - 1], a[i - 2], a[i - 3], a[i - 4], a[i]});
      }
    }
  }
  cout << l + 1 << " " << r - 1;
  return 0;
}
