#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
const int inf = 1000000000;
const int maxn = 100010;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%1d", &b[i]);
  }
  int l = -inf, r = inf, pre = 0;
  for (int i = 1; i <= 3; i++) {
    pre += b[i];
  }
  for (int i = 5; i <= n; i++) {
    pre = pre - b[i - 5] + b[i - 1];
    if (pre != 4 && pre != 0) continue;
    if (b[i] == b[i - 1]) {
      continue;
      if (b[i] == 1 && pre == 4) {
        int x = a[i - 4];
        for (int j = i - 3; j <= i; j++) {
          x = min(x, a[j]);
        }
        r = max(r, x);
      }
      if (b[i] == 0 && pre == 0) {
        int x = a[i - 4];
        for (int j = i - 3; j <= i; j++) {
          x = max(x, a[j]);
        }
        l = min(l, x);
      }
    } else {
      if (b[i] == 1) {
        for (int j = i - 4; j <= i; j++) {
          l = max(l, a[j] + 1);
        }
      } else {
        for (int j = i - 4; j <= i; j++) {
          r = min(r, a[j] - 1);
        }
      }
    }
  }
  cout << l << " " << r;
}
