#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string b1;
  cin >> b1;
  int b[100010];
  for (int i = 0; i < n; i++) {
    b[i] = b1[i] - '0';
  }
  int r = pow(10, 9);
  int l = -1 * pow(10, 9);
  for (int i = 4; i < n; i++) {
    if (b[i] == b[i - 1]) {
      continue;
    } else {
      if (b[i] == 0 && b[i - 1] == 1 && b[i - 2] == 1 && b[i - 3] == 1 &&
          b[i - 4] == 1) {
        int temp =
            min(a[i], min(a[i - 1], min(a[i - 2], min(a[i - 3], a[i - 4]))));
        r = min(r, temp - 1);
      } else if (b[i] == 1 && b[i - 1] == 0 && b[i - 2] == 0 && b[i - 3] == 0 &&
                 b[i - 4] == 0) {
        int temp =
            max(a[i], max(a[i - 1], max(a[i - 2], max(a[i - 3], a[i - 4]))));
        l = max(l, temp + 1);
      }
    }
  }
  cout << l << " " << r;
}
