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

const int maxN = 5e5 + 10;
char ans[maxN];

struct Sum {
    int i, val;

    Sum(int i) : i(i) { scanf("%d", &val); }

    bool operator<(Sum const &o) const { return val < o.val; }

    void give_ans(bool x) { ans[i] = x ? 'T' : 'N'; }
};

vector<Sum> t;
int N;


int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i)
        t.emplace_back(i);
    sort(t.begin(), t.end());

    long long sum_prev = 0;
    int last_unable = -1, val = t[0].val, lastval = 0;

    for (int i = 1; i < N; ++i) {
        if (t[i].val != val) {
            long long amount = i - lastval;
            long long total_mass = val;
            if (sum_prev > 0)
                total_mass = sum_prev + val * amount;
            if (total_mass <= t[i].val)
                last_unable = i - 1;

            sum_prev += val * amount;
            val = t[i].val;
            lastval = i;
        }
    }

    if (t[0].val == t[N - 1].val)
        last_unable = N;
    for (int i = 0; i < N; ++i)
        t[i].give_ans(i > last_unable);
    printf("%s\n", ans);
}