#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const long long inF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
int a[maxn];
char s[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  cin >> s + 1;
  int l = -1e9, r = 1e9;
  for (int i = 5; i <= n; i++) {
    if (s[i - 1] == s[i - 2] && s[i - 1] == s[i - 3] && s[i - 1] == s[i - 4]) {
      if (s[i - 1] == '1') {
        if (s[i] == '0') {
          int tmp = 1e9;
          for (int j = i; j >= i - 4; j--) tmp = min(a[j], tmp);
          r = min(r, tmp - 1);
        } else {
          int tmp = 1e9;
          for (int j = i; j >= i - 4; j--) tmp = min(a[j], tmp);
          r = max(r, tmp + 1);
        }
      } else {
        if (s[i] == '0') {
          int tmp = -1e9;
          for (int j = i; j >= i - 4; j--) tmp = max(a[j], tmp);
          l = min(l, tmp - 1);
        } else {
          int tmp = -1e9;
          for (int j = i; j >= i - 4; j--) tmp = max(a[j], tmp);
          l = max(l, tmp + 1);
        }
      }
      if (l > r) r = l;
    }
  }
  cout << l << " " << r << '\n';
  return 0;
}
