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 <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

const long MAX =  500009;

long S[MAX];
long I[MAX];

bool comp(long l, long r) {
  return S[l] < S[r];
}
struct cmp{
  bool operator()(long l, long r) const {
    return S[l] < S[r];
  }
};

int main() {
  std::ios_base::sync_with_stdio(0);
  long n;
  std::cin >> n;
  for (long i=0;i<n;++i) I[i] = i;
  for (long i=0;i<n;++i) std::cin >> S[i];
  std::sort(I, I+n, comp);
  std::multiset<long, cmp> M;
  long sum = 0, tsum = 0;
  long si = 0;
  for (long ii=0;ii<n;++ii) {
    long i = I[ii];
    if (sum <= S[i]) M.clear();
    if (S[i] != S[I[0]]) {
      M.insert(i);
    } else M.clear();
    sum += S[i];
  }
  std::set<long> K;
  for(long i : M) K.insert(S[i]);
  for (long i=0;i<n;++i) std::cout << (K.count(S[i]) > 0 ? 'T' : 'N');
  return 0;
}