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
#include "bits/stdc++.h" // Ignacy Boehlke
using namespace std;     // XIII LO Szczecin
template<class A, class B> ostream& operator << (ostream& os, const pair<A, B>& p) {return os << '{' << p.first << ", " << p.second << '}';}
template<class T> auto operator << (ostream& os, const T& v) -> decltype(v.begin(), os) {os << '{';for (auto i : v) os << i << ", ";return os << '}';}
#ifdef DEBUG
#define D(x...) x
#else
#define D(x...)
#endif
#define LN(x) D(cerr << #x << ": " << x << ' ')
#define LOG(x) D(cerr << #x << ": " << x << '\n')
#define ssize(x) ((int)x.size())
#define FOR(a, b, c) for(int a = (b); a <= (c); ++a)
#define REP(a, b) FOR(a, 0, b - 1)
#define ALL(x) (x).begin(), (x).end()
#define fi first
#define se second
using ll = long long;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> in(n);
    ll s = 0;
    REP(i, n) scanf("%d", &in[i]), s += in[i];
    vector<int> vals = in;
    sort(ALL(vals));
    vector<pair<int, int>> p = {{vals[0], 1}};
    FOR(i, 1, n - 1) {
        if (vals[i] == vals[i - 1]) ++p.back().se;
        else p.emplace_back(vals[i], 1);
    }
    LOG(p);
    int res = p.back().fi;
    p.emplace_back(p.back().fi, 0);
    for (int i = ssize(p) - 2; i; --i) {
        if (s > p[i + 1].fi) res = p[i].fi - 1;
        else break;
        s -= (ll)p[i].fi * p[i].se;
    }
    REP(i, n) putchar(in[i] > res ? 'T' : 'N');
    putchar('\n');
}