#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long l = -1e9;
  long long r = 1e9;
  string str;
  vector<long long> a(n);
  vector<long long> b(n);
  vector<long long> l_max;
  vector<long long> l_min;
  vector<long long> r_max;
  vector<long long> r_min;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> str;
  for (long long i = 0; i < n; i++) {
    b[i] = static_cast<long long>(str[i] == '1');
  }
  vector<long long> state(n);
  vector<long long> summ(n);
  long long now;
  for (long long i = 4; i < n; i++) {
    now = 0;
    for (long long j = 0; j < 5; j++) {
      now = min(now, a[i - j]);
    }
    summ[i] = now;
  }
  bool zero = false, one = false;
  for (long long i = 3; i < n; i++) {
    zero = false, one = false;
    for (long long j = 0; j < 4; j++) {
      if (b[i - j] == 0)
        zero = true;
      else
        one = true;
    }
    if (one && zero)
      state[i] = 0;
    else if (zero)
      state[i] = 1;
    else
      state[i] = 2;
  }
  for (long long i = 4; i < n; i++) {
    if (b[i] == 0 && b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 &&
        b[i - 4] == 1) {
      r = min(min(r, a[i] - 1), min(min(a[i - 1] - 1, a[i - 2] - 1),
                                    min(a[i - 4] - 1, a[i - 3] - 1)));
    }
    if (b[i] == 1 && b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 &&
        b[i - 4] == 0) {
      l = max(max(l, a[i] + 1), max(max(a[i - 1] + 1, a[i - 2] + 1),
                                    max(a[i - 4] + 1, a[i - 3] + 1)));
    }
  }
  cout << l << ' ' << r;
}
