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
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef pair<lld, lld> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

constexpr int N = 1 << 20;

lld d[N];
lld t[N];
pll p[N];
int n, k = 0, l;
lld siz = 0, res = -1;

int main(){
	scanf("%d", &n);
	
	for (int i = 0; i < n; ++i) {
		scanf("%lld", d + i);
		t[i] = d[i];
	}
	
	sort(t, t + n);
	
	p[0] = mp(t[0], t[0]); // waga ryby, suma wag
	
	for (int i = 1; i < n; ++i) {
		if (t[i] != t[i - 1]) {
			++k;
			p[k] = mp(t[i], t[i]);
		}
		else {
			p[k].ss += t[i];
		}
	}
	
	++k;
	
	if (k == 1) {
		for (int i = 0; i < n; ++i) {
			printf("N");
		}
		return 0;
	}
	
	siz = p[0].ss + p[1].ss;
	
	for (int i = 1; i < k;) {
		l = i + 1;
		while (l < k && siz > p[l].ff) {
			siz += p[l].ss;
			++l;
		}
		
		if (l >= k) {
			res = p[i].ff;
			break;
		}
		
		i = l;
		siz += p[l].ss;
	}
	
	
	for (int i = 0; i < n; ++i) {
		printf("%c", d[i] >= res ? 'T' : 'N');
	}
	
	
	return 0;
}