#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  string s;
  cin >> s;
  long long l = -1e15, r = 1e15;
  for (int i = 4; i < s.length(); i++) {
    if (s[i] == s[i - 1])
      continue;
    else if (s[i] == '1') {
      long long maxi = -1e15;
      for (int j = i; j >= (i - 4); j--) maxi = max(maxi, arr[j]);
      l = max(l, maxi + 1);
    } else {
      long long mini = 1e15;
      for (int j = i; j >= (i - 4); j--) mini = min(mini, arr[j]);
      r = min(r, mini - 1);
    }
  }
  if (r == 1e15 && l == -1e15) {
    cout << -1000000000 << " " << 1000000000;
  } else if (r == 1e15) {
    cout << l << " " << 1000000000;
  } else
    cout << l << " " << r;
}
