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
53
54
55
56
57
58
#include <bits/stdc++.h>
#define QED return 0;}
#define main() int main(){
#define ll long long
using namespace std;

ll n, a;
ll t[500007];
ll t2[500007];
ll oo = 1e18 + 7;

bool spr(ll x){
	ll xx = t[x];
	for(int i = 1; i <= n; i++){
		if(xx > t[n]) return 1;
		if(i == x){
			continue;
		}
		if(xx > t[i]){
			xx += t[i];
		}
		else return 0;
		if(xx > t[n]) return 1;
	}
	if(xx > t[n]) return 1;
	return 0;
}

ll bin(ll p, ll k){
	ll s = 0;
	while(p < k){
		s = (p + k) / 2;
		if(spr(s)) k = s;
		else  p = s + 1;
	}
	return t[p];
}

main()
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> t[i];
		t2[i] = t[i];
	}
	sort(t + 1, t + n + 1);
	t[n + 1] = oo;
	
	a = bin(1, n + 1);
	for(int i = 1; i <= n; i++){
		if(t2[i] >= a) cout << 'T';
		else cout << 'N';
	}
	
QED