#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
char b[100005];
int r = 1000000000, l = -1000000000;
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  cin >> b;
  for (int i = 4; i < n; i++) {
    if (b[i] != b[i - 1]) {
      if (b[i] == '0') {
        r = min({r, a[i] - 1, a[i - 1] - 1, a[i - 2] - 1, a[i - 3] - 1,
                 a[i - 4] - 1});
      } else {
        l = max({l, a[i] + 1, a[i - 1] + 1, a[i - 2] + 1, a[i - 3] + 1,
                 a[i - 4] + 1});
      }
    }
  }
  if (l > r) l = r;
  cout << l << ' ' << r << endl;
  return 0;
}
