#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MAXN = 100000 + 9;
int n;
int num[MAXN];
char b[MAXN];
int judge(int x) {
  bool tmp = 1;
  for (int i = 1; i <= 4; i++) {
    if (b[x - i] != '0') tmp = 0;
  }
  if (tmp) return 0;
  tmp = 1;
  for (int i = 1; i <= 4; i++) {
    if (b[x - i] != '1') tmp = 0;
  }
  if (tmp) return 1;
  return -1;
}
int calc_max(int x) {
  int re = -INF;
  for (int i = 0; i <= 4; i++) {
    re = max(re, num[x - i]);
  }
  return re;
}
int calc_min(int x) {
  int re = INF;
  for (int i = 0; i <= 4; i++) {
    re = min(re, num[x - i]);
  }
  return re;
}
void solve() {
  int l = -INF, r = INF;
  for (int i = 5; i <= n; i++) {
    if (b[i] == b[i - 1]) continue;
    int jud = judge(i);
    if (jud == -1) continue;
    if (jud == 0) {
      int maxx = calc_max(i);
      l = max(l, maxx);
    } else {
      int minn = calc_min(i);
      r = min(r, minn);
    }
  }
  printf("%d %d\n", l + 1, r - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  scanf("%s", b + 1);
  solve();
  return 0;
}
