#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
void disp(vector<long long> v) {
  for (auto u : v) cout << u << " ";
  cout << '\n';
}
void solve() {
  long long n, l = -MOD, r = MOD, mx, mi;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  string b;
  cin >> b;
  for (long long i = 4; i < ((int)(b).size()); i++) {
    if (b[i] == '1' && b[i - 1] == '0') {
      mx = *max_element(a.begin() + i - 4, a.begin() + i + 1);
      l = max(l, mx + 1);
    } else if (b[i] == '0' && b[i - 1] == '1') {
      mi = *min_element(a.begin() + i - 4, a.begin() + i + 1);
      r = min(r, mi - 1);
    }
  }
  cout << l << " " << r << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
