#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 10;
string b;
long long a[maxn];
long long pre[maxn];
void solve() {
  memset(pre, 0, sizeof(pre));
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cin >> b;
  pre[0] = 0;
  for (long long i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + b[i - 1] - '0';
  }
  long long lL, lR, rL, rR;
  lL = rL = -INF;
  lR = rR = INF;
  for (long long i = 5; i <= n; i++) {
    long long x = pre[i - 1] - pre[i - 5];
    if (x == 0) {
      long long mx = -INF;
      for (long long j = i; j > i - 5; j--) {
        mx = max(mx, a[j]);
      }
      if (b[i - 1] == '1') {
        lL = max(lL, mx);
      } else {
        lR = min(lR, mx + 1);
      }
    } else if (x == 4) {
      long long mi = INF;
      for (long long j = i; j > i - 5; j--) {
        mi = min(mi, a[j]);
      }
      if (b[i - 1] == '1') {
        rL = max(rL, mi - 1);
      } else {
        rR = min(rR, mi);
      }
    }
  }
  cout << lL + 1 << " " << rR - 1 << endl;
}
int main() { solve(); }
