#include <bits/stdc++.h>
using namespace std;
void solve();
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
int max_(int a, int b, int c, int d, int e) {
  int t[] = {a, b, c, d, e};
  sort(t, t + 5);
  return t[4];
}
int min_(int a, int b, int c, int d, int e) {
  int t[] = {a, b, c, d, e};
  sort(t, t + 5);
  return t[0];
}
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int b[n];
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) b[i] = s[i] - '0';
  int l = -1000000000;
  int r = 1000000000;
  for (int i = 4; i < n; i++) {
    if (b[i - 1] == b[i - 2] && b[i - 2] == b[i - 3] && b[i - 3] == b[i - 4]) {
      if (b[i] == 0 && b[i - 1] == 0) {
        l = min(max_(a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]) - 1, l);
      }
      if (b[i] == 1 && b[i - 1] == 0) {
        l = max(l, max_(a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]) + 1);
      }
      if (b[i] == 0 && b[i - 1] == 1) {
        r = min(r, min_(a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]) - 1);
      }
      if (b[i] == 1 && b[i - 1] == 1) {
        r = max(min_(a[i], a[i - 1], a[i - 2], a[i - 3], a[i - 4]) + 1, r);
      }
    }
  }
  cout << l << " " << r << endl;
}
