#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
const int M = 1e9;
int a[N], b[N];
int initmin(int l, int r) {
  int d = M;
  for (int i = l; i <= r; i++) d = min(d, a[i]);
  return d;
}
int initmax(int l, int r) {
  int d = -M;
  for (int i = l; i <= r; i++) d = max(d, a[i]);
  return d;
}
int main() {
  int n;
  int l, s, r, ll, rr;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) scanf("%1d", &b[i]);
    l = -M;
    r = M;
    for (int i = 5; i <= n; i++) {
      if (b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 && b[i - 4] == 0) {
        ll = initmax(i - 4, i);
        if (b[i] == 0)
          l = min(ll, l);
        else
          l = max(ll + 1, l);
      } else if (b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 &&
                 b[i - 4] == 1) {
        rr = initmin(i - 4, i);
        if (b[i] == 1)
          r = max(r, rr);
        else
          r = min(r, rr - 1);
      }
    }
    cout << l << " " << r << endl;
  }
  return 0;
}
