1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
#define PB push_back
using namespace std;
using ll=long long;
const int MAXN=(500005);
int n;
vector<ll>v, V;
set<ll>s;
ll pref[MAXN];

bool git(ll x){
	while(x>=1 && pref[x]>v[x-1] && v[x]*(ll)(v.size()-x)!=(ll)pref[x]){
		x--;
	}
	if(x==0) return 1;
	return 0;
}

int main()
{
	cin>>n;
	for(ll x, i=1; i<=n; i++){
		cin>>x; v.PB(x); V.PB(x); s.insert(x);
	}
	if(s.size()==1){
		for(int i=1; i<=n; i++) cout<<"N";
		return 0;
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	//cout<<v[0]<<" ";
	pref[v.size()]=0;
	for(int i=v.size()-1; i>=0; i--){
		pref[i]=pref[i+1]+v[i];
	}
	ll pocz=0, kon=v.size()-1;
	while(pocz<kon-1){
		ll sr=(pocz+kon)/2;
	//	cout<<sr<<" ";
		if(git(sr)){
			pocz=sr;
		}
		else{
			kon=sr-1;
		}
	}
	if(pocz+1<v.size() && git(pocz+1)) pocz++;
	for(int i=0; i<n; i++){
		if(V[i]>=v[pocz]) cout<<"T";
		else cout<<"N";
	}
}