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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct wzium {
    int val;
    // char wnk= 'x';
    int it;

    bool operator< (const wzium b) {
        return this->val < b.val;
    }
};

void wypisz (const vector <char> &wnk) {
    for (char k: wnk)
        cout << k;
    cout << '\n';
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector <wzium> V;
    for (int i=0;i<n;i++) {
        wzium x;
        cin >> x.val;
        x.it= i;
        V.push_back(x);
    }

    sort(V.begin(), V.end());

    vector <long long> sumPref(n);
    sumPref[0]= V[0].val;
    for (int i=1;i<n;i++)
        sumPref[i]= sumPref[i-1]+V[i].val;

    vector <char> wnk(n, 'x');
    wnk[V[0].it]= 'N';
    for (int i=1;i<n;i++) {
        if (V[i].val != V[i-1].val)
            break;
        wnk[V[i].it]= 'N';
    }

    if (wnk[V[n-1].it] == 'N') {
        wypisz(wnk);
        return 0;
    }
    else
        wnk[V[n-1].it]= 'T';


    for (int i=n-2;i>0;i--) {
        if (wnk[V[i].it] == 'N')
            break;

        if (V[i].val == V[i+1].val) {
            wnk[V[i].it]= wnk[V[i+1].it];
            continue;
        }

        if (sumPref[i] > V[i+1].val)
            wnk[V[i].it]= 'T';
        else {
            wnk[V[i].it]= 'N';
            while (i>=2) {
                wnk[V[i-1].it]= 'N';
                i--;
            }
            break;
        }
    }

    wypisz(wnk);

    return 0;
}