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 <bits/stdc++.h>
#pragma GCC optimize(0fast)
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define st first
#define nd second
#define pb push_back
#define INF 1000000000
#define mil 1000000
#define modulo 1000000007
using namespace std;
typedef long long ll;

using namespace std;
pair<int,int> tab[1000001];
ll pref[1000001];
ll powt[1000001];
int res[1000001];
int dokad(int n){
    int i = 1;
    while(i < n and tab[i].first == tab[i-1].first){
        i++;
    }
    return i;
}

int main(){
	BOOST;
	int n; cin >> n;
	for(int i=0; i<n; i++){
		int a; cin >> a;
		tab[i] = {a,i};
	}
    if(n == 2){
        if(tab[0].first > tab[1].first)
            cout << "TN";
        else if(tab[0].first < tab[1].first)
            cout << "NT";
        else if(tab[0].first == tab[1].first)
            cout << "NN";
        return 0;
    }
	sort(tab, tab + n);
    if(tab[0].first == tab[n-1].first){
        for(int i=0; i<n; i++){
            cout << "N";
        }
        return 0;
    }
	int x = dokad(n);
    ll sum = 0;
    for(int i=0; i<x; i++){
        res[tab[i].second] = 0;
        sum += tab[i].first;
    }
    res[tab[n-1].second] = 1;	
    for(int i=x; i<n-1; i++){
        sum += tab[i].first;
        if(sum > tab[i + 1].first){
            res[tab[i].second] = 2;
        }
        else{
            res[tab[i].second] = 0;
        }
    }
    bool czy = false;
        for(int i=n-1; i>=0; i--){
            if(res[tab[i].second] == 0){
                res[tab[i].second] = 0;
                czy = true;
            }
            else{
                if(czy == false)
                    res[tab[i].second] = 1;
                else
                    res[tab[i].second] = 0;
            }
        }
    for(int i=0; i<n; i++){
        if(res[i] == 1)
            cout << "T";
        else
            cout << "N";
    }
}