#include <bits/stdc++.h>
using namespace std;
const int N = 1000111;
int n, m, arr[N], l = -1000000001, r = 1000000001;
string s;
bool bf(int id, int x) {
  for (int i = id - 1, j = 0; j < 4; j++, i--) {
    if ((s[i] - '0') != x) return 0;
  }
  return 1;
}
int minbf(int id) {
  int mn = 1000000001;
  for (int i = id, j = 0; j < 5; j++, i--) {
    mn = min(mn, arr[i]);
  }
  return mn;
}
int maxbf(int id) {
  int mx = -1000000001;
  for (int i = id, j = 0; j < 5; j++, i--) {
    mx = max(mx, arr[i]);
  }
  return mx;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> s;
  for (int i = 4; i < s.size(); i++) {
    if (s[i] == '0' && bf(i, 1)) {
      if (r == 1000000001) {
        r = minbf(i) - 1;
      } else {
        int mnbf = minbf(i);
        if (mnbf > r || s[i - 1] == s[i]) {
        } else
          r = min(mnbf - 1, r);
      }
    }
    if (s[i] == '1' && bf(i, 0)) {
      if (l == -1000000001) {
        l = maxbf(i) + 1;
      } else {
        int mxbf = maxbf(i) + 1;
        if (mxbf < l || s[i - 1] == s[i]) {
        } else
          l = max(mxbf + 1, l);
      }
    }
  }
  if (r == 1000000001) r--;
  if (l == -1000000001) l++;
  cout << l << " " << r << endl;
}
