#include <bits/stdc++.h>
using namespace std;
const int __ = 100005;
int a[__];
char b[__];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  scanf("%s", b + 1);
  int l = -1e9, r = 1e9;
  for (int i = (2); i <= (n); i++)
    if (b[i] != b[i - 1]) {
      if (b[i] == '1') {
        int maxx = INT_MIN;
        for (int j = (i - 4); j <= (i); j++)
          if (a[j] > maxx) maxx = a[j];
        l = max(l, maxx + 1);
      } else {
        int minn = INT_MAX;
        for (int j = (i - 4); j <= (i); j++)
          if (a[j] < minn) minn = a[j];
        r = min(r, minn - 1);
      }
    }
  printf("%d %d\n", l, r);
  return 0;
}
