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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500000 + 5;

int nextInt() { int n; scanf("%d", &n); return n; }

struct Catfish {
	long long m;
	int pos;

	bool operator<(const Catfish &oth) const {
		if (m != oth.m) return m < oth.m;
		return pos < oth.pos;
	}
};

vector<Catfish> myData;
char res[N];

bool check(int pos, int n) {
	long long sum = myData[pos].m;
	for (int i = 0; i < n; ++i) {
		if (i == pos) continue;
		if (sum <= myData[i].m) return false;
		sum += myData[i].m;
	}
	return true;
}

void solve() {
	int n = myData.size();
	sort(myData.begin(), myData.end());

	if (myData[0].m == myData.back().m) {
		// none
		for (int i = 0; i < n; ++i) res[i] = 'N';
		return;
	}
	int a = 0;
	int b = n - 1;
	while (a + 1 < b) {
		int c = (a + b) / 2;
		if (check(c, n))
			b = c;
		else
			a = c;
	}
	for (int i = 0; i < b; ++i) res[myData[i].pos] = 'N';
	for (int i = b; i < n; ++i) res[myData[i].pos] = 'T';
}

int main() {
	int n = nextInt();
	myData.resize(n);
	for (int i = 0; i < n; ++i) myData[i] = { nextInt(), i };
	res[n] = 0;

	solve();
	printf("%s\n", res);
	
	return 0;
}