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