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
#include <cstdio>
#include <vector>
#include <algorithm>


using namespace std;


struct catfish
{
	unsigned index, mass;
	unsigned long long mass2;
};


bool compare(const catfish a, const catfish b)
{
	return a.mass < b.mass;
}


int main()
{
	unsigned n;
	scanf("%u", &n);

	vector<catfish> v(n);
	for (unsigned i = 0; i < n; ++i)
	{
		v[i].index = i;
		scanf(" %u", &v[i].mass);
	}

	sort(v.begin(), v.end(), compare);

	unsigned long long s = v[0].mass2;
	for (unsigned i = 0; i < n; ++i)
	{
		s += v[i].mass;
		if (v[i].mass == v[0].mass) v[i].mass2 = v[0].mass;
		else v[i].mass2 = s;
	}

	vector<bool> r(n);
	if (v[0].mass != v[n - 1].mass) r[v[n - 1].index] = true;
	for (int i = n - 2; i >= 0; --i)
		if (r[v[i + 1].index] && v[i].mass2 > v[i + 1].mass) r[v[i].index] = true;

	for (vector<bool>::reference c : r)
	{
		if (c) printf("T");
		else printf("N");
	}

	return 0;
}