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
/*
    Piotr Bieńkowski
    bbienkos@gmail.com
    Akademickie Liceum Ogólnokształcące Politechniki Wrocławskiej
*/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define debug(x); cerr << #x << " = " << x << "\n";
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define int long long

const int N = 5e5 + 7;

int n;
int tab[N];
int org[N];
__int128_t pref[N];

unordered_map<int, bool> S;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> tab[i];
        org[i] = tab[i];
    }
    sort(tab, tab + n);
    pref[0] = tab[0];
    for(int i = 1; i < n; i++)  pref[i] = min((long long)(tab[i] + pref[i - 1]), 1000000000LL);

    int last = -1;
    int wsk = n - 2;
    for(int i = n - 1; i >= 0;)
    {
        while(wsk > 0 && tab[wsk] == tab[i]) wsk--;
        if(tab[wsk] == tab[i]) break;
        int tmp = 1;
        if(pref[wsk] != 0)
        {
            tmp = i - wsk;
        }
        if(pref[wsk] + tmp * tab[i] > last || i == n - 1)
        {
            S[tab[i]] = true;
            last = tab[i];
        }
        i = wsk;
    }

    for(int i = 0; i < n; i++)
    {
        if(S[org[i]]) cout << "T";
        else cout << "N";
    }
    cout << "\n";
}