#include <bits/stdc++.h>
using namespace std;
const int mod = 100000007;
int n, d, k;
int a[200000];
string b;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> b;
  int l = -1e9;
  int r = 1e9;
  for (int i = 4; i < n; i++) {
    if (b[i] == '1') {
      if (b[i - 1] == '0' && b[i - 2] == '0' && b[i - 3] == '0' &&
          b[i - 4] == '0') {
        l = max(l, a[i - 1]);
        l = max(l, a[i - 2]);
        l = max(l, a[i - 3]);
        l = max(l, a[i - 4]);
        l = max(l, a[i]);
      }
    } else {
      if (b[i - 1] == '1' && b[i - 2] == '1' && b[i - 3] == '1' &&
          b[i - 4] == '1') {
        r = min(r, a[i - 1]);
        r = min(r, a[i - 2]);
        r = min(r, a[i - 3]);
        r = min(r, a[i - 4]);
        r = min(r, a[i]);
      }
    }
  }
  l++, r--;
  if (r < l) l = r;
  cout << l << " " << r << endl;
  return 0;
}
