#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10;
int n, k, L = -1e9, R = 1e9, Mx, Mn, X;
string s;
int a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> s;
  s = '.' + s;
  for (int i = 5; i <= n; i++) {
    Mn = 1e9;
    Mx = -1e9;
    X = 0;
    for (int j = i; j >= i - 4; j--) X += s[i] == s[j];
    if (X != 1) continue;
    for (int j = i; j >= i - 4; j--) {
      Mn = min(a[j], Mn);
      Mx = max(a[j], Mx);
    }
    if (s[i] == '0')
      R = min(R, Mn - 1);
    else if (s[i] == '1')
      L = max(L, Mx + 1);
  }
  cout << L << " " << R;
}
