#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, inf = 1e9 + 10;
int a[maxn], b[maxn];
char bb[maxn] = {0};
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  scanf("%s", bb);
  for (int i = 1; i <= n; i++) b[i] = bb[i - 1] - '0';
  int l = -inf, r = inf;
  for (int i = 5; i <= n; i++) {
    if (b[i] == 0 && b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 &&
        b[i - 4] == 1) {
      int tmp = min(a[i - 4], a[i - 3]);
      tmp = min(tmp, a[i - 2]);
      tmp = min(tmp, a[i - 1]);
      tmp = min(tmp, a[i]);
      r = min(r, tmp - 1);
    } else if (b[i] == 1 && b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 &&
               b[i - 4] == 0) {
      int tmp = max(a[i - 4], a[i - 3]);
      tmp = max(tmp, a[i - 2]);
      tmp = max(tmp, a[i - 1]);
      tmp = max(tmp, a[i]);
      l = max(l, tmp + 1);
    }
  }
  if (l == -inf && r == inf)
    l = r = -inf + 10;
  else if (l == -inf)
    l = -inf + 10;
  else if (r == inf)
    r = inf - 10;
  printf("%d %d", l, r);
  return 0;
}
