#include <bits/stdc++.h>
using namespace std;
int a[100005];
string b;
int main() {
  int lo = -1e9;
  int hi = 1e9;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  cin >> b;
  b = "0" + b;
  for (int i = 5; i <= n; i++) {
    if (b[i] == b[i - 1]) continue;
    if (b[i - 1] == '1' && b[i] == '0')
      hi = min(
          hi,
          (min(a[i], min(a[i - 1], min(a[i - 2], min(a[i - 3], a[i - 4]))))) -
              1);
    else
      lo = max(
          lo,
          (max(a[i], max(a[i - 1], max(a[i - 2], max(a[i - 3], a[i - 4]))))) +
              1);
  }
  cout << lo << " " << hi << endl;
}
