#include <bits/stdc++.h>
using namespace std;
long long lans = -1e9, rans = 1e9, n, tab[500010];
char z[500010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int a = 1; a <= n; a++) cin >> tab[a];
  for (int a = 1; a <= n; a++) {
    cin >> z[a];
    if (a > 1 && z[a] != z[a - 1]) {
      if (z[a - 1] == '0')
        for (int b = 1; b <= 5; b++) lans = max(lans, tab[a - b + 1]);
      else
        for (int b = 1; b <= 5; b++) rans = min(rans, tab[a - b + 1]);
    }
  }
  cout << lans + 1 << " " << rans - 1 << '\n';
  return 0;
}
