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
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;

pair <long long, int> sum[N];
long long pref[N];
bool wyn[N];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		long long a;
		cin >> a;
		sum[i] = make_pair(a, i);
	}
		
	sort(sum + 1, sum + 1 + n);
	
	for(int i = 1; i <= n; i++)
		pref[i] = pref[i - 1] + sum[i].first;
	
	bool krol = 0;
	int lim = 0;
	
	for(int i = 1; i <= n; i++){
		if(i <= lim || (i != 1 && sum[1].first == sum[i].first)) continue;
		if(krol){
			wyn[sum[i].second] = 1;
			continue;
		}
		
		if(i == n){
			wyn[sum[i].second] = 1;
			continue;
		}
		
		int j = i + 1;
		
		while(j <= n){
			if(pref[j - 1] <= sum[j].first) break;
			j++;
		}
		
		if(j == n + 1){
			krol = 1;
			wyn[sum[i].second] = 1;
		}
		
		else lim = j - 1;
		
	}
	
	for(int i = 1; i <= n; i++){
		if(wyn[i]) cout << "T";
		else cout << "N";
	}
	
	cout << "\n"; 
	
}