#include <bits/stdc++.h>
using namespace std;
const long long N = 1001 * 1001, MOD = 1e9 + 7;
long long a[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) s[i] -= '0';
  long long l = -1e9, r = 1e9;
  for (long long i = 4; i < n; i++) {
    long long cnt = 0;
    for (long long j = i - 4; j < i; j++) cnt += s[i];
    if (s[i] != s[i - 1]) {
      if (s[i] == 1)
        l = max(l, *max_element(a + i - 4, a + i + 1) + 1);
      else
        r = min(r, *min_element(a + i - 4, a + i + 1) - 1);
    } else {
    }
  }
  cout << l << ' ' << r << endl;
}
