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
#include <bits/stdc++.h>

using namespace std;

typedef uint64_t ll;

bool answ[500001];

map<ll, pair<ll, vector<int>>> fishe;

int main() {
    int n;
    cin >> n;

    ll total_sum = 0;

    for(int i = 1; i <= n; i++) {
        int a;
        scanf("%d", &a);
        fishe[a].second.push_back(i);
        total_sum += a;
    }

    ll acc = 0;
    for(auto &i: fishe) {
        if(!acc)  i.second.first = i.first;
        else  i.second.first = acc + (i.first * i.second.second.size());
        acc += i.first * i.second.second.size();
    }

    if(fishe.rbegin()->second.first == total_sum) {
        for (auto i = fishe.rbegin(); i != fishe.rend(); i++) {
            for (int j: i->second.second) answ[j] = true;

            if (next(i) != fishe.rend() && next(i)->second.first <= i->first) break;
        }
    }

    for(int i = 1; i <= n; i++) {
        if(answ[i]) printf("T");
        else printf("N");
    }

    cout << endl;

    return 0;
}