#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B>
bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-7;
long long inf = sizeof(long long) == sizeof(long long) ? 2e18 : 1e9;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  string s;
  cin >> s;
  long long l = -1000000010, r = 1000000010;
  for (int i = 4; i < n; i++)
    if (s[i - 4] == s[i - 3] && s[i - 4] == s[i - 2] && s[i - 4] == s[i - 1] &&
        s[i - 1] != s[i]) {
      long long t;
      if (s[i] == '1') {
        t = -inf;
        t = max(t, a[i]);
        t = max(t, a[i - 1]);
        t = max(t, a[i - 2]);
        t = max(t, a[i - 3]);
        t = max(t, a[i - 4]);
        l = max(l, t + 1);
      } else {
        t = inf;
        t = min(t, a[i]);
        t = min(t, a[i - 1]);
        t = min(t, a[i - 2]);
        t = min(t, a[i - 3]);
        t = min(t, a[i - 4]);
        r = min(r, t - 1);
      }
    }
  cout << max(l, -1000000000ll) << " " << min(r, 1000000000ll) << endl;
}
