#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, true : false;
}
template <class T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, true : false;
}
inline long long read(void) {
  long long x, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
int n, a[200005], f[200005], g[200005], sum;
char b[200005];
int l = -1e9, r = 1e9;
int main(void) {
  n = read();
  for (int i = (1); i <= (n); ++i) a[i] = read();
  scanf("%s", b + 1);
  for (int i = (5); i <= (n); ++i) {
    f[i] = -1e9, g[i] = 1e9;
    for (int j = (i - 4); j <= (i); ++j) chkmax(f[i], a[j]), chkmin(g[i], a[j]);
  }
  for (int i = (5); i <= (n); ++i) {
    sum = 0;
    for (int j = (i - 4); j <= (i - 1); ++j)
      if (b[j] == '1') sum += b[j] - '0';
    if (sum == 4 && b[i] == '0')
      chkmin(r, g[i] - 1);
    else if (sum == 0 && b[i] == '1')
      chkmax(l, f[i] + 1);
  }
  printf("%d %d\n", l, r);
}
