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