#include <bits/stdc++.h>
using namespace std;
int n, a[100005], l = -1000000000, r = 1000000000;
string b;
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] == '0' && b[i - 1] == '1') {
      int minim = a[i];
      for (int j = i - 4; j < i; ++j) minim = min(minim, a[j]);
      r = min(r, minim - 1);
    } else if (b[i] == '1' && b[i - 1] == '0') {
      int maxim = a[i];
      for (int j = i - 4; j < i; ++j) maxim = max(maxim, a[j]);
      l = max(l, maxim + 1);
    }
  }
  cout << l << " " << r << "\n";
  return 0;
}
