#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  long long b[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  string str;
  cin >> str;
  for (long long int i = 0; i < n; i++) b[i] = str[i] - '0';
  long long l = -1e9;
  long long r = 1e9;
  for (long long int i = 4; i < n; i++) {
    if (b[i] == 1 && b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 &&
        b[i - 4] == 0)
      l = max(
          l,
          max(a[i], max(a[i - 1], max(a[i - 2], max(a[i - 3], a[i - 4])))) + 1);
    else if (b[i] == 0 && b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 &&
             b[i - 4] == 1)
      r = min(
          r,
          min(a[i], min(a[i - 1], min(a[i - 2], min(a[i - 3], a[i - 4])))) - 1);
  }
  cout << l << ' ' << r << '\n';
  return 0;
}
