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
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>

using namespace std;

int next(set<int>::iterator it) {
    advance(it, 1);
    return *it;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, sum;
    vector<int> sumy;
    set<int> sumy_sort;
    unordered_map<int, int> sumy_dane;
    unordered_map<int, bool> mozliwe;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> sum;
        sumy.push_back(sum);
        sumy_sort.insert(sum);
        sumy_dane[sum]++;
    }

    long long curr, suma = 0;
    int ryba, ile_ryb;
    set<int>::iterator it;
    bool eating = false;
    unordered_map<int, int> eat_from;
    if (sumy_sort.size() > 1) {
        it = sumy_sort.begin();
        advance(it, sumy_sort.size() - 1);
        mozliwe[*it] = true;
    }
    it = sumy_sort.begin();
    for (int i = 1; i < sumy_sort.size(); i++) {
        ryba = *it;
        ile_ryb = sumy_dane[ryba];
        curr = suma + ryba * (i > 1 ? ile_ryb : 1);
        suma += ryba * ile_ryb;
        if (next(it) < curr) {
            if (!eating) {
                eating = true;
                eat_from[ryba] = suma;
            } else {
                eat_from[ryba] += ryba * ile_ryb;
            }
        } else if (eating) {
            eat_from.clear();
            eating = false;
        }
        advance(it, 1);
    }
    if (sumy_sort.size() > 1) {
        it = sumy_sort.begin();
        advance(it, sumy_sort.size() - 1);
        eat_from[*it] = 1;
    }
    for (int sum : sumy) {
        if (eat_from[sum] != 0)
            cout << "T";
        else
            cout << "N";
    }
    return 0;
}