#include <bits/stdc++.h>
using namespace std;
int a[100005], len, l = -1e9, r = 1e9;
char b[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> len;
  for (int i = 0; i < len; i++) cin >> a[i];
  cin >> b;
  for (int i = 4; i < len; i++) {
    if (b[i] == '1' && b[i - 1] == '0')
      l = max(l, *max_element(a + i - 4, a + i + 1) + 1);
    else if (b[i] == '0' && b[i - 1] == '1')
      r = min(r, *min_element(a + i - 4, a + i + 1) - 1);
  }
  cout << l << ' ' << r << endl;
  return 0;
}
