#include <bits/stdc++.h>
using namespace std;
const int con = pow(10, 9);
int many;
int s[100010];
int t[100010];
int minL = -con;
int maxL = con;
int minR = -con;
int maxR = con;
int is(int at) {
  if (!t[at - 4] && !t[at - 3] && !t[at - 2] && !t[at - 1]) {
    if (!t[at]) return 1;
    if (t[at]) return 2;
  }
  if (t[at - 4] && t[at - 3] && t[at - 2] && t[at - 1]) {
    if (!t[at]) return 4;
    if (t[at]) return 3;
  }
  return 0;
}
int mins(int at) {
  int now = s[at];
  for (int i = 1; i <= 4; i++) now = min(now, s[at - i]);
  return now;
}
int maxs(int at) {
  int now = s[at];
  for (int i = 1; i <= 4; i++) now = max(now, s[at - i]);
  return now;
}
int main() {
  cin >> many;
  for (int i = 1; i <= many; i++) cin >> s[i];
  for (int i = 1; i <= many; i++) {
    char c;
    cin >> c;
    t[i] = c - '0';
  }
  for (int i = 5; i <= many; i++) {
    int k = is(i);
    if (k == 1) maxL = min(maxL, maxs(i));
    if (k == 2) minL = max(minL, maxs(i) + 1);
    if (k == 3) minR = max(minR, mins(i));
    if (k == 4) maxR = min(maxR, mins(i) - 1);
  }
  cout << minL << " " << maxR;
  return 0;
}
