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