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
#include <bits/stdc++.h>

#define  _2137 0

#define pb push_back
#define ff first
#define ss second

using namespace std;

bool ans[500009];

int main() {
    
    int n;
    scanf("%d",&n);

    int tab[n+1];

    vector <pair <int,int>> que;

    unsigned long long out=0;

    for(int i=0;i<n;++i){
        
        scanf("%d",&tab[i]);
        
        //if(tab[i]>maX) maX=tab[i];

        que.pb({tab[i],i});

    }
    sort(que.begin(),que.end());
/*
    for(int i=0;i<n;++i){
        cout<<que[i].ff<<" "<<que[i].ss<<endl;
    }

*/
    if(que[0].ff==que[n-1].ff){
        for(int i=0;i<n;++i){
            printf("N");
        }
        return _2137;
    }

    int j=0,last=n-1;
    
    while(j<n-1){
        
        out+=que[j].ff;
        
        if(out<=que[j+1].ff) {
            last=j;
        }
        //cout<<out<<" "<<que[j+1].ff<<" "<<last<<endl;
        ++j;
    }
    j=last+1;


    //cout<<j<<endl;
    while(que[0].ff==que[j].ff && j<=n){
        ++j;
    }

    
    while(que[j].ff==que[j-1].ff && j>0){
        --j;
    }
    

    for(int i=j;i<n;++i){

        ans[que[i].ss]=true;

    }

    for(int i=0;i<n;++i){
        if(ans[i]) printf("T");
        else printf("N");
    }


	return _2137;
}