#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	string s;
	cin >> s;
	L = 1, R = N + 1;
	while (R - L > 1) {
		int mid = (R + L) / 2;
		auto w = v;
		for (auto &i : w)i = i >= mid;
		vector<pair<int, int>>x;
		int bef = -1;
		for (int i = 1; i < N; i++) {
			if (w[i] != w[i - 1]) {
				x.push_back({ i - 1 - bef,bef + 1 });
				bef = i - 1;
			}
		}
		x.push_back({ N - 1 - bef,bef + 1 });
		if (x.size() == 1) {
			if (w.front() == 0)R = mid;
			else L = mid;
			continue;
		}
		set<pair<int, int>>len0;
		set<pair<int, int>>len1;
		set<pair<int, int>>p0;
		set<pair<int, int>>p1;
		for (int i = 1; i + 1 < x.size(); i++) {
			if (w[x[i].second]) {
				len1.emplace(x[i]);
				p1.emplace(x[i].second, x[i].first);
			}
			else {
				len0.emplace(x[i]);
				p0.emplace(x[i].second, x[i].first);
			}
		}
		if (w.front() == 0) {
			len0.emplace(x[0].first + 200000, x[0].second - 200000);
			p0.emplace(x[0].second - 200000, x[0].first + 200000);
		}
		else {
			len1.emplace(x[0].first + 200000, x[0].second - 200000);
			p1.emplace(x[0].second - 200000, x[0].first + 200000);
		}
		if (w.back() == 0) {
			len0.emplace(x.back().first + 200000, x.back().second);
			p0.emplace(x.back().second, x.back().first + 200000);
		}
		else {
			len1.emplace(x.back().first + 200000, x.back().second);
			p1.emplace(x.back().second, x.back().first + 200000);
		}
		bool flag = true;
		int minus0 = 0;
		int minus1 = 0;
		int mnum = 0;
		int Mnum = 0;
		for (auto i : s) {
			if (i == 'M') {
				Mnum++;
				minus1--;
				minus0++;
				while (len0.size() && len0.begin()->first <= minus0) {
					int p = len0.begin()->second;
					int addlen = len0.begin()->first;
					p0.erase({ len0.begin()->second,len0.begin()->first });
					len0.erase(len0.begin());
					auto it = p1.lower_bound({ p ,0 });
					auto nx = *prev(it);
					swap(nx.first, nx.second);
					nx.first += addlen + it->second;
					len1.erase({ prev(it)->second,prev(it)->first });
					p1.erase(prev(it));
					len1.erase({ it->second,it->first });
					p1.erase(it);
					len1.insert(nx);
					p1.insert({ nx.second,nx.first });
				}
			}
			else {
				mnum++;
				minus1++;
				minus0--;
				while (len1.size() && len1.begin()->first <= minus1) {
					int p = len1.begin()->second;
					int addlen = len1.begin()->first;
					p1.erase({ len1.begin()->second,len1.begin()->first });
					len1.erase(len1.begin());
					auto it = p0.lower_bound({ p ,0 });
					auto nx = *prev(it);
					swap(nx.first, nx.second);
					nx.first += addlen + it->second;
					len0.erase({ prev(it)->second,prev(it)->first });
					p0.erase(prev(it));
					len0.erase({ it->second,it->first });
					p0.erase(it);
					len0.insert(nx);
					p0.insert({ nx.second,nx.first });
				}
			}
		}
	//	cout << "mid " << mid << endl;
	//	cout << "mnum " << mnum << endl;
		for (auto i : len0) {
	//		cout << " 0 " << i.second - mnum << " " << i.first + i.second - 1 - Mnum << endl;
			if (i.second - mnum <= 0 && i.first + i.second - Mnum - 1 >= 0)flag = false;
		}
		if (flag)L = mid;
		else R = mid;
	}
	cout << L << endl;
}

Measured memory_bytes: 6220