#include <bits/stdc++.h>
int a[100010];
char b[100010];
int main() {
  int damn = 1;
  int n, l = -1000000000, r = 1000000000, cnt = 0, z = 0;
  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 (!damn) {
      if (++cnt == 4) damn = 1;
    } else if (b[i] != b[i - 1]) {
      if (b[i] == '0' && b[i - 1] == '1') {
        z = r + 1;
        for (int j = 0; j < 5; ++j) z = std::min(z, a[i - j]);
        r = z - 1;
      } else if (b[i] == '1' && b[i - 1] == '0') {
        z = l - 1;
        for (int j = 0; j < 5; ++j) z = std::max(z, a[i - j]);
        l = z + 1;
      }
      damn = 0;
      cnt = 1;
    }
  }
  printf("%d %d\n", l, r);
  return 0;
}
