#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
long long M = 1e9 + 7;
vector<int> prm;
int CNT[maxn + 10];
long long CHOOSE[maxn + 10][maxn + 10];
vector<int> vc;
inline bool check(int num) {
  return 0;
  int sum = 0;
  while (num) {
    sum += num % 10;
    num /= 10;
  }
  if (sum == 10) return true;
  return false;
}
const int N = 1e6 + 10;
int a[N + 10], c[N + 10];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> s;
  int l = -1e9, r = 1e9;
  for (int i = 4; i < s.size(); i++)
    if (s[i] == '1' && s[i - 1] == '1' && s[i - 2] == '1' && s[i - 3] == '1' &&
        s[i - 4] == '1') {
      int mn = 1e9;
      for (int j = i; j >= i - 4; j--) mn = min(mn, a[j]);
      r = max(r, mn);
    } else if (s[i] == '0' && s[i - 1] == '1' && s[i - 2] == '1' &&
               s[i - 3] == '1' && s[i - 4] == '1') {
      int mn = 1e9;
      for (int j = i; j >= i - 4; j--) mn = min(mn, a[j]);
      r = min(r, mn - 1);
    } else if (s[i] == '0' && s[i - 1] == '0' && s[i - 2] == '0' &&
               s[i - 3] == '0' && s[i - 4] == '0') {
      int mx = -1e9;
      for (int j = i; j >= i - 4; j--) mx = max(mx, a[j]);
      l = min(l, mx);
    } else if (s[i] == '1' && s[i - 1] == '0' && s[i - 2] == '0' &&
               s[i - 3] == '0' && s[i - 4] == '0') {
      int mx = -1e9;
      for (int j = i; j >= i - 4; j--) mx = max(mx, a[j]);
      l = max(l, mx + 1);
    }
  cout << l << ' ' << r;
  return 0;
}
