#include <bits/stdc++.h>
using namespace std;
template <typename T>
using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
  s << "[";
  for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
  s << "]";
  return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, const pair<A, B>& p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
  return _out(s, begin(c), end(c));
}
bool debug = 0;
template <typename T>
void DEBUG(const T& x) {
  if (debug) cerr << x;
}
template <typename T, typename... Args>
void DEBUG(const T& head, const Args&... tail) {
  if (debug) {
    cerr << head;
    DEBUG(tail...);
  }
}
const int N = 100000 + 5;
int ans[N], arr[N];
int main(int argc, char* argv[]) {
  if (argc > 1 and string(argv[1]) == "-D") debug = 1;
  if (!debug) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  string ss;
  cin >> ss;
  int l = -1000000000, r = 1000000000;
  for (int i = 4; i < n; i++) {
    int x = ss[i] - '0';
    if (x == 1 and ans[i - 1] == 0 and ans[i - 2] == 0 and ans[i - 3] == 0 and
        ans[i - 4] == 0) {
      l = max(
          l, max({arr[i], arr[i - 1], arr[i - 2], arr[i - 3], arr[i - 4]}) + 1);
    } else if (x == 0 and ans[i - 1] == 1 and ans[i - 2] == 1 and
               ans[i - 3] == 1 and ans[i - 4] == 1) {
      r = min(
          r, min({arr[i], arr[i - 1], arr[i - 2], arr[i - 3], arr[i - 4]}) - 1);
    }
    ans[i] = x;
  }
  cout << l << ' ' << r << '\n';
  return 0;
}
