#include <bits/stdc++.h>
using namespace std;
int r = 1e9, l = -1e9, n, a[100050], b[100050];
char c;
int read() {
  int x = 0, f = 1;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0';
  return x * f;
}
void getb() {
  while (!isdigit(c)) c = getchar();
  for (int i = 1; i <= n; i++) {
    b[i] = c - '0';
    c = getchar();
  }
}
bool che(int w, int p) {
  if (b[w - 1] != p) return 0;
  if (b[w - 2] != p) return 0;
  if (b[w - 3] != p) return 0;
  if (b[w - 4] != p) return 0;
  return 1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) a[i] = read();
  getb();
  for (int i = 5; i <= n; i++) {
    if (b[i] == 0 && che(i, 1)) {
      for (int j = 0; j <= 4; j++) {
        if (a[i - j] <= r) r = a[i - j] - 1;
      }
    }
    if (b[i] == 1 && che(i, 0)) {
      for (int j = 0; j <= 4; j++) {
        if (a[i - j] >= l) l = a[i - j] + 1;
      }
    }
  }
  cout << l << " " << r;
}
