#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int i;
  for (i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  for (i = 0; i < n; i++) {
    int x = (int)(s[i] - '0');
    b[i] = x;
  }
  int l, r;
  l = 1000000000;
  l *= -1;
  r = -1 * l;
  for (i = 4; i < n; i++) {
    if (b[i] != b[i - 1]) {
      if (b[i] == 1) {
        int j;
        for (j = i; j >= i - 4; j--) l = max(l, a[j] + 1);
      } else {
        int j;
        for (j = i; j >= i - 4; j--) r = min(r, a[j] - 1);
      }
    }
  }
  cout << l << " " << r << endl;
  return 0;
}
