#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int a[222222];

ii getL(set<ii> &s, int x) //largest<x
{
	auto it=s.lower_bound(mp(x,0));
	if(it==s.begin()) return mp(-1,0);
	return (*prev(it));
}

ii getR(set<ii> &s, int x) //largest>x
{
	auto it=s.lower_bound(mp(x,0));
	if(it==s.end()) return mp(-1,0);
	return (*it);
}

int solve(vi vec, string s)
{
	int n=vec.size();
	int delta[2]={0,0};
	/*
	cerr<<"\nSOLVE\n";
	for(int v:vec)
	{
		cerr<<v<<' ';
	}
	cerr<<'\n';
	*/
	int run=1;
	vector<ii> runs;
	for(int i=1;i<n;i++)
	{
		if(vec[i]==vec[i-1])
		{
			run++;
		}
		else
		{
			runs.pb(mp(run,vec[i-1])); run=1;
		}
	}
	runs.pb(mp(run,vec[n-1]));
	set<ii> pos[2];
	set<ii> pq[2];
	for(int i=0;i<runs.size();i++)
	{
		pos[runs[i].se].insert(mp(i,runs[i].fi));
		pq[runs[i].se].insert(mp(runs[i].fi,i));
	}
	for(int i=0;i<s.length();i++)
	{
		int cur=0;
		if(s[i]=='M'){cur^=1;}
		delta[cur]++; delta[cur^1]--;
		set<ii>::iterator I[2][2];
		for(int j=0;j<2;j++)
		{
			I[j][0]=pos[j].begin();
			I[j][1]=pos[j].end();
		}
		bool fr=0; bool en=0;
		if(pos[cur^1].empty()){fr=1;}
		else
		{
			if(!pos[cur].empty()&&((*I[cur][0]).fi<(*I[cur^1][0]).fi))
			{
				fr=1;
			}
			if(!pos[cur].empty()&&((*prev(I[cur][1])).fi>(*prev(I[cur^1][1])).fi))
			{
				en=1;
			}
		}
		//cerr<<"FR EN "<<fr<<' '<<en<<'\n';
		if(fr)
		{
			auto it = pos[cur].begin();
			ii nw = mp(it->fi,it->se-1);
			pos[cur].erase(it); pos[cur].insert(nw);
			pq[cur].erase(mp(nw.se+1,nw.fi)); pq[cur].insert(mp(nw.se,nw.fi));
		}
		if(en)
		{
			auto it = prev(pos[cur].end());
			ii nw = mp(it->fi,it->se-1);
			pos[cur].erase(it); pos[cur].insert(nw);
			pq[cur].erase(mp(nw.se+1,nw.fi)); pq[cur].insert(mp(nw.se,nw.fi));
		}
		/*
		cerr<<"BEFORE LOOP\n";
		cerr<<"POS 0\n";
		for(ii x:pos[0])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"POS 1\n";
		for(ii x:pos[1])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"PQ 0\n";
		for(ii x:pq[0])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"PQ 1\n";
		for(ii x:pq[1])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		*/
		while(!pq[cur^1].empty()&&(*pq[cur^1].begin()).fi+delta[cur^1]==0)
		{
			ii tmp = (*pq[cur^1].begin());
			int p = tmp.se;
			ii l = getL(pos[cur], p);
			ii r = getR(pos[cur], p);
			//cerr<<l.fi<<' '<<l.se<<' '<<r.fi<<' '<<r.se<<'\n';
			if(l.fi>=0) pos[cur].erase(l); 
			if(r.fi>=0) pos[cur].erase(r);
			if(l.fi>=0) pq[cur].erase(mp(l.se,l.fi));
			if(r.fi>=0) pq[cur].erase(mp(r.se,r.fi));
			int delt=0;
			if(l.fi>=0&&r.fi>=0) delt=delta[cur];
			if(l.fi<0&&r.fi<0) delt=-delta[cur];
			pos[cur].insert(mp(max(l.fi,r.fi),l.se+r.se+delt));
			pq[cur].insert(mp(l.se+r.se+delt,max(l.fi,r.fi)));
			pq[cur^1].erase(tmp); pos[cur^1].erase(mp(tmp.se,tmp.fi));
		}
		/*
		cerr<<"AFTER LOOP\n";
		cerr<<"POS 0\n";
		for(ii x:pos[0])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"POS 1\n";
		for(ii x:pos[1])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"PQ 0\n";
		for(ii x:pq[0])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		cerr<<"PQ 1\n";
		for(ii x:pq[1])
		{
			cerr<<x.fi<<' '<<x.se<<'\n';
		}
		*/
	}
	//cerr<<"OUTPUT "<<pq[0].size()<<' '<<pq[1].size()<<'\n';
	return (pq[0].empty());
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	string s; cin>>s;
	int lo=1; int hi=n;
	int ans=0;
	while(lo<=hi)
	{
		int mid=(lo+hi)>>1;
		vector<int> vec;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=mid) vec.pb(1);
			else vec.pb(0);
		}
		if(solve(vec,s))
		{
			ans=mid;lo=mid+1;
		}
		else hi=mid-1;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 7876