#include <bits/stdc++.h>
using namespace std;
class Solver {
 public:
  const int INF = static_cast<const int>(1e9);
  int n{};
  vector<int> a;
  string b;
  int l{}, r{};
  Solver() = default;
  Solver &inputData() {
    cin >> n;
    a.resize(static_cast<unsigned long>(n));
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    cin >> b;
    return *this;
  }
  Solver &solve() {
    l = -INF;
    r = INF;
    for (int i = 4; i < n; ++i) {
      if (b[i] == '0') {
        if (isOnes(i - 1)) {
          r = min(r, getMin(i) - 1);
        }
      } else {
        if (isZeros(i - 1)) {
          l = max(l, getMax(i) + 1);
        }
      }
    }
    return *this;
  }
  Solver &outputAnswer() {
    cout << l << " " << r << endl;
    return *this;
  }

 private:
  bool isOnes(int p) {
    return (b[p] == '1' && b[p - 1] == '1' && b[p - 2] == '1' &&
            b[p - 3] == '1');
  }
  int getMin(int p) {
    return min(min(min(a[p], a[p - 1]), min(a[p - 2], a[p - 3])), a[p - 4]);
  }
  bool isZeros(int p) {
    return (b[p] == '0' && b[p - 1] == '0' && b[p - 2] == '0' &&
            b[p - 3] == '0');
  }
  int getMax(int p) {
    return max(max(max(a[p], a[p - 1]), max(a[p - 2], a[p - 3])), a[p - 4]);
  }
};
int main() {
  Solver solver;
  solver.inputData();
  solver.solve();
  solver.outputAnswer();
  return 0;
}
