#include <bits/stdc++.h>
using namespace std;
int sa[100005], s1[100005];
char s[100005];
int save[6];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int a = 1; a <= n; a++) scanf("%d", &sa[a]);
    scanf("%s", s + 1);
    int l = -1000000000, r = 1000000000;
    for (int a = 1; a <= n; a++) s1[a] = s[a] - 48;
    for (int a = 5; a <= n; a++) {
      for (int b = a - 4; b <= a; b++) save[b - (a - 5)] = sa[b];
      sort(save + 1, save + 1 + 5);
      if (s1[a - 1] == 0 && s1[a - 2] == 0 && s1[a - 3] == 0 &&
          s1[a - 4] == 0) {
        if (s1[a] == 1 && s1[a - 1] != 1)
          l = max(l, save[5] + 1);
        else {
          continue;
        }
      } else if (s1[a - 1] == 1 && s1[a - 2] == 1 && s1[a - 3] == 1 &&
                 s1[a - 4] == 1) {
        if (s1[a] == 0 && s1[a - 1] != 0) {
          r = min(r, save[1] - 1);
        } else
          continue;
      } else {
        continue;
      }
    }
    printf("%d %d\n", l, r);
  }
  return 0;
}
