#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  string s;
  cin >> s;
  int u1 = -1000000000, u2 = 1000000000;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1] && s[i] == '1') {
      int y1 = -1000000000;
      for (int i1 = i, c = 0; c < 5; i1--, c++) {
        y1 = max(y1, ar[i1]);
      }
      y1 = y1 + 1;
      u1 = max(u1, y1);
    } else if (s[i] != s[i - 1] && s[i] == '0') {
      int y1 = 1000000000;
      for (int i1 = i, c = 0; c < 5; i1--, c++) {
        y1 = min(y1, ar[i1]);
      }
      y1 = y1 - 1;
      u2 = min(u2, y1);
    }
  }
  cout << u1 << " " << u2 << endl;
  return 0;
}
