#include <bits/stdc++.h>
using namespace std;
long long n, a[111111], l, r;
long long minn(int m, int n) {
  long long ans = 1e9;
  for (int i = n; i <= m; ++i) ans = min(ans, a[i]);
  return ans;
}
long long maxx(int m, int n) {
  long long ans = -1e9;
  for (int i = n; i <= m; ++i) ans = max(ans, a[i]);
  return ans;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  ;
  l = -1e9;
  r = 1e9;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  string s;
  cin >> s;
  for (int i = 4; i < s.size(); ++i) {
    if (s[i] == s[i - 1]) continue;
    if (s[i] == '1') {
      long long _max = maxx(i, i - 4) + 1;
      l = max(_max, l);
    } else {
      long long _min = minn(i, i - 4) - 1;
      r = min(_min, r);
    }
  }
  cout << l << ' ' << r;
  return 0;
}
