#include <bits/stdc++.h>
using ll = long long;
using namespace std;
char brr[120000];
int arr[120000];
int mn(int a, int b, int c, int d, int e) {
  return min(a, min(b, min(c, min(d, e))));
}
int mx(int a, int b, int c, int d, int e) {
  return max(a, max(b, max(c, max(d, e))));
}
const int INF = 1000000007;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  scanf("%s", brr + 1);
  int ll = -INF, lr = INF, rl = -INF, rr = INF, l, r;
  for (int i = 5; i <= n; i++) {
    int sum = brr[i - 4] + brr[i - 3] + brr[i - 2] + brr[i - 1] - '0' * 4;
    if (sum == 0) {
      if (brr[i] == '1')
        ll = max(mx(arr[i - 4], arr[i - 3], arr[i - 2], arr[i - 1], arr[i]) + 1,
                 ll);
    }
    if (sum == 4) {
      if (brr[i] == '0')
        rr = min(mn(arr[i - 4], arr[i - 3], arr[i - 2], arr[i - 1], arr[i]) - 1,
                 rr);
    }
  }
  if (ll != -INF)
    l = ll;
  else
    l = -(INF - 7);
  if (rr != INF)
    r = rr;
  else
    r = INF - 7;
  printf("%d %d\n", l, r);
  return 0;
}
