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
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

const int MAX_N = 5 * 100 * 1000 + 5;

map<int, int> counts_of_kind;
map<int, long long> sums_of_smaller;

int fish[MAX_N];

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

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> fish[i];
    counts_of_kind[fish[i]] += 1;
  }

  long long sum = 0;
  for (auto elem : counts_of_kind) {
    sums_of_smaller[elem.first] = sum;
    sum += (long long)elem.first * elem.second;
  }

  long long smallest_possible = 1000 * 1000 * 1000 + 1;
  long long to_eat = 0;
  bool first = true;
  for (auto it = sums_of_smaller.rbegin(); it != sums_of_smaller.rend(); it++) {
    if (first) {
      if (counts_of_kind[it->first] > 1)
        to_eat = it->first;
      first = false;
    }

    long long mass;

    if (it->second > 0)
      mass = (long long)it->first * counts_of_kind[it->first] + it->second;
    else
      mass = it->first;

    if (mass <= to_eat) {
      break;
    }

    to_eat = it->first;
    smallest_possible = it->first;
  }

  for (int i = 0; i < n; i++) {
    if (fish[i] >= smallest_possible)
      cout << "T";
    else
      cout << "N";
  }

  return 0;
}