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>
using namespace std;

#define ll long long
#define pb push_back
#define st first
#define nd second

vector<pair<ll, ll>> v;
bool r[500009];

bool f(ll x) {
	ll w = v[x].st;
	for(ll i=0;i<v.size();i++) {
		if(i != x) {
			if(w > v[i].st) {
				w+=v[i].st;
			} else {
				return false;
			}
		}
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin >> n;
	for(ll i=0;i<n;i++) {
		ll x;
		cin >> x;
		v.pb({x, i});
	}
	sort(v.begin(), v.end());
	ll s = -1;
	ll e = v.size();
	while(e-s>1) {
		ll m = (e+s)/2;
		if(f(m)) 
			e = m;
		else
			s = m;
	}
	for(ll i=e;i<v.size();i++)
		r[v[i].nd] = true;
	for(ll i=0;i<n;i++)
		cout << (r[i] ? 'T' : 'N');
	cout << "\n";
}