#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    vec.push_back(x);
  }
  string s;
  cin >> s;
  int L_left_bound = -1e9 - 1;
  int R_right_bound = 1e9 + 1;
  for (int i = 4; i < n; ++i) {
    bool ok = true;
    int mini = INT_MAX;
    int maxi = INT_MIN;
    for (int j = i - 1; j > i - 4; --j) {
      mini = min(mini, vec[j]);
      maxi = max(maxi, vec[j]);
      if (s[j] != s[j - 1]) {
        ok = false;
        break;
      }
    }
    mini = min(mini, vec[i]);
    mini = min(mini, vec[i - 4]);
    maxi = max(maxi, vec[i]);
    maxi = max(maxi, vec[i - 4]);
    if (ok) {
      if (s[i] == '0' and s[i - 1] == '1') {
        R_right_bound = min(R_right_bound, mini);
      } else if (s[i] == '1' and s[i - 1] == '0') {
        L_left_bound = max(L_left_bound, maxi);
      }
    }
  }
  if (L_left_bound + 2 == R_right_bound) {
    cout << L_left_bound + 1 << " " << L_left_bound + 1 << endl;
  } else {
    cout << L_left_bound + 1 << " " << R_right_bound - 1 << endl;
  }
  return 0;
}
