#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 11;
int sum[maxn], b[maxn];
char str[maxn];
int main() {
  int n;
  int l = -1e9;
  int r = 1e9;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &sum[i]);
    b[i] = sum[i];
  }
  getchar();
  scanf("%s", str);
  int flag;
  for (int i = 4; i < n; i++) {
    flag = 1;
    if (str[i] == '1') {
      for (int j = i - 1; j >= i - 4; j--) {
        if (str[j] != '0') {
          flag = 0;
          break;
        }
      }
      if (flag) {
        sort(b + i - 4, b + i + 1);
        l = max(b[i] + 1, l);
      }
    } else {
      for (int j = i - 1; j >= i - 4; j--) {
        if (str[j] != '1') {
          flag = 0;
          break;
        }
      }
      if (flag) {
        sort(b + i - 4, b + i + 1);
        r = min(b[i - 4] - 1, r);
      }
    }
  }
  printf("%d %d\n", l, r);
}
