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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <map>
#include <iostream>

constexpr int MAX_N = 500000;
long long input[MAX_N];
std::map<long long, long long> map;
int n;

inline void readInput() {
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        std::cin >> input[i];
        map[input[i]]++;
    }
}

inline void solveFor1Type() {
    for (int i = 0; i < n; i++)
        std::cout << 'N';
}

inline void solveFor2Types() {
    long long lowerElement = map.begin()->first;

    for (int i = 0; i < n; i++)
    {
        if (input[i] == lowerElement)
            std::cout << 'N';
        else
            std::cout << 'T';
    }
}

inline void solveForMoreThan2Types() {
    long long firstT = 0;
    auto elementAfterLast = map.end();

    long long sum = 0;
    for (auto i = map.begin(); i != map.end(); i++) {
        sum += i->first * i->second;
        i->second = sum;
    }

    for (auto i = map.rbegin(); i != map.rend(); i++) {
        auto next = i;
        next++;
        if (next == map.rend()) {
            firstT = i->first;
            break;
        }

        if (next->second <= i->first) {
            firstT = i->first;
            break;
        }
    }

    for (int i = 0; i < n; i++) {
        if (input[i] < firstT || input[i] == map.begin()->first)
            std::cout << 'N';
        else
            std::cout << 'T';
    }
}

void solve() {
    readInput();

    // if only 1 element then all N
    if (map.size() == 1) {
        solveFor1Type();
        return;
    }

    // if only 2 elements then lower N, biggest T
    if (map.size() == 2) {
        solveFor2Types();
        return;
    }

    // more than 2 elements
    solveForMoreThan2Types();
}


int main() {
    solve();
    return 0;
}